3 using System.Collections.Generic;
12 [AddComponentMenu(
"Liberi/Line Renderer Hooks")]
13 [RequireComponent(typeof(LineRenderer))]
15 [Script(ScriptRole.View)]
18 public Transform EndPoint1;
19 public Transform EndPoint2;
20 public int VertexCount = 2;
21 public bool FixedZ =
true;
27 _line = GetComponent<LineRenderer>();
34 if (EndPoint1 == null || EndPoint2 == null)
37 _line.SetVertexCount(VertexCount);
39 Vector3 delta = EndPoint2.position - EndPoint1.position;
40 float length = delta.magnitude;
41 Vector3 direction = length == 0 ? Vector3.zero : delta / length;
42 float z = transform.position.z;
44 for (
int i = 0; i < VertexCount; i++)
46 float progress = (float)i / (VertexCount - 1);
48 Vector3 newVertex = EndPoint1.position + direction * progress * length;
53 _line.SetPosition(i, newVertex);
Allows a line renderer to automatically hook onto and follow two end points.