Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
LineProject.cs
Go to the documentation of this file.
1 using UnityEngine;
2 
3 namespace droid.Runtime.Utilities.GameObjects.NeodroidCamera {
7  [RequireComponent(typeof(LineRenderer))]
8  [ExecuteInEditMode]
9  public class LineProject : MonoBehaviour {
10  LineRenderer _line_renderer = null;
11  [SerializeField] Vector3 _direction = Vector3.down;
12  [SerializeField] float _length = 30f;
13 
14  Vector3 _old_pos = Vector3.zero;
15 
16  void Awake() {
17  this._line_renderer = this.GetComponent<LineRenderer>();
18  this.Project();
19  }
20 
21  void OnEnable() { this.Project(); }
22 
23  void Update() {
24  if (Application.isPlaying) {
25  if (this.transform.position != this._old_pos) {
26  this.Project();
27  }
28  }
29  }
30 
31  void Project() {
32  var position = this.transform.position;
33  if (Physics.Raycast(position, this._direction, out var ray, this._length)) {
34  this._line_renderer.SetPositions(new[] {position, ray.point});
35  }
36  }
37  }
38 }