Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using VRTK;
- public class Pen : MonoBehaviour {
- public float LineDistance = 0.1f; // Trackを置き直す距離
- public GameObject track; // 軌跡
- VRTK_InteractableObject io; // コントローラ用
- Vector3 start_pos; // 開始位置
- GameObject current_track; // 先っちょ
- GameObject pen_traks; // 軌跡置き場
- void Start()
- {
- io = transform.parent.GetComponent<VRTK_InteractableObject>();
- // 軌跡置き場
- pen_traks = new GameObject("PenTracks");
- pen_traks.transform.parent = null;
- }
- void Update()
- {
- // 使ってる?
- if (io.IsUsing() == true)
- {
- // 一定距離動いた?
- if (Vector3.Distance(start_pos, transform.position) > LineDistance)
- {
- // 開始位置保存
- start_pos = transform.position;
- if (current_track != null)
- {
- // 昔のやつを、軌跡を入れる用のオブジェクトに突っ込む
- current_track.transform.parent = pen_traks.transform;
- }
- // 新しい軌跡を作成
- current_track = Instantiate(track, transform.position, Quaternion.identity);
- current_track.SetActive(true);
- // 自分の子にする
- current_track.transform.parent = transform;
- }
- }
- else
- {
- // 線引いていた?
- if (current_track != null)
- {
- // 昔のやつを、軌跡を入れる用のオブジェクトに突っ込む
- current_track.transform.parent = pen_traks.transform;
- current_track = null;
- // 開始位置を遠くにしとく
- start_pos = Vector3.one * 100f;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment