Guest User

Untitled

a guest
Feb 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using VRTK;
  5.  
  6. public class Pen : MonoBehaviour {
  7. public float LineDistance = 0.1f; // Trackを置き直す距離
  8. public GameObject track; // 軌跡
  9.  
  10. VRTK_InteractableObject io; // コントローラ用
  11. Vector3 start_pos; // 開始位置
  12. GameObject current_track; // 先っちょ
  13. GameObject pen_traks; // 軌跡置き場
  14.  
  15. void Start()
  16. {
  17. io = transform.parent.GetComponent<VRTK_InteractableObject>();
  18.  
  19. // 軌跡置き場
  20. pen_traks = new GameObject("PenTracks");
  21. pen_traks.transform.parent = null;
  22. }
  23.  
  24. void Update()
  25. {
  26. // 使ってる?
  27. if (io.IsUsing() == true)
  28. {
  29. // 一定距離動いた?
  30. if (Vector3.Distance(start_pos, transform.position) > LineDistance)
  31. {
  32. // 開始位置保存
  33. start_pos = transform.position;
  34. if (current_track != null)
  35. {
  36. // 昔のやつを、軌跡を入れる用のオブジェクトに突っ込む
  37. current_track.transform.parent = pen_traks.transform;
  38. }
  39. // 新しい軌跡を作成
  40. current_track = Instantiate(track, transform.position, Quaternion.identity);
  41. current_track.SetActive(true);
  42. // 自分の子にする
  43. current_track.transform.parent = transform;
  44. }
  45. }
  46. else
  47. {
  48. // 線引いていた?
  49. if (current_track != null)
  50. {
  51. // 昔のやつを、軌跡を入れる用のオブジェクトに突っ込む
  52. current_track.transform.parent = pen_traks.transform;
  53. current_track = null;
  54.  
  55. // 開始位置を遠くにしとく
  56. start_pos = Vector3.one * 100f;
  57. }
  58. }
  59. }
  60. }
Add Comment
Please, Sign In to add comment