- Home /
Removing the first point form a lineRenderer
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.
Answer by highpockets · Mar 24, 2019 at 06:12 PM
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[i] = lineRenderer.GetPosition[i + 1];
}
lineRenderer.SetPositions(newPositions);
I know it's been almost two years but I need your or someone else's help with a similar problem. I tried your code, and it almost worked exactly how I wanted (just one thing, instead of brackets ([]) you should use parenthesis(())) otherwise it will show an error, but other than that, it's working fine.
The thing is I don't want the line to delete itslef completely, just to delete itslelf until there is an specific amount of points in the array, so that the line has a constant length.
I am very new using unity, and I just found out about line renderer, so please provide a code or a simple explanation otherwise I might not understand :) . If someone could just modify the code provided by highpockets would be great.
Thank you!
Your answer
Follow this Question
Related Questions
Remove points of LineRenderer? 1 Answer
LineRenderer GetPosition? not there. 2 Answers
Points attached to a prefab 0 Answers