Chaotic Motion  1.0
ChaosTrail.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 
5 [RequireComponent(typeof(LineRenderer))]
14 public class ChaosTrail : MonoBehaviour {
15 
17  public float minVertexDistance = 0.1f;
19  public float maxPoints = 500;
20 
21  private LineRenderer lineRenderer;
22 
23  // use an array as a ring buffer to avoid shuffling as points are added.
24  private List<Vector3> points;
25 
26  // Use this for initialization
27  void Awake () {
28  Init();
29  }
30 
31  public void Init () {
32  lineRenderer = GetComponent<LineRenderer>();
33  points = new List<Vector3>();
34  }
35 
40  public void AddPoint(Vector3 point) {
41  if (points.Count >= maxPoints) {
42  points.RemoveAt(0);
43  }
44  points.Add(point);
45  // copy the points into the LineRenderer
46  lineRenderer.positionCount = points.Count;
47  int i = 0;
48  foreach (Vector3 p in points) {
49  lineRenderer.SetPosition(i++, p);
50  }
51  }
52 
53 }
void AddPoint(Vector3 point)
Adds a point to the trail.
Definition: ChaosTrail.cs:40
float maxPoints
Number of points in the trail.
Definition: ChaosTrail.cs:19
float minVertexDistance
Distance interval for points to be added to the renderer.
Definition: ChaosTrail.cs:17
Chaos trail. Update a trail using a LineRenderer. This allows the path between points to be filled in...
Definition: ChaosTrail.cs:14