I have a lineRenderer the draws a line by adding points.
Now I want to delete the oldest point if the lineRenderer contains more than an “x” amount of points.
I thought this would by very easy but I can’t find an simple way of doing it.
Just shift all the points. To get rid of the first one, just over write it with the second one and keep overwriting all the way along until you reach the end. You can do this easily in a for loop:
Edit: (thought I’d share some code)
LineRenderer lineRenderer = GetComponent<LineRenderer>();
int newPositionCount = lineRenderer.positionCount - 1;
Vector3[] newPositions = new Vector3[newPositionCount];
for (int i = 0; i < newPositionCount; i++){
newPositions *= lineRenderer.GetPosition[i + 1];*
}
lineRenderer.SetPositions(newPositions);