At the top :
public List<Vector3> lineRendererPositions = new List<Vector3>();
Then a method :
Vector3[] GetLinePointsInWorldSpace()
{
var positions = new Vector3[lineRenderer.positionCount];
//Get the positions which are shown in the inspector
lineRenderer.GetPositions(positions);
//the points returned are in world space
return positions;
}
Then in the Update :
private void Update()
{
lineRendererPositions.AddRange(GetLinePointsInWorldSpace());
}
The problem is the Listi s getting bigger and bigger so the game get laggy and laggy. I could add a line before to make a new instance for the List :
private void Update()
{
lineRendererPositions = new List<Vector3>();
lineRendererPositions.AddRange(GetLinePointsInWorldSpace());
}
but I'm not sure this is a good way to Update the List. I want that when it's getting the positions from the GetLinePointsInWorldSpace if they are not the same as in the lineRendererPositions List then Update (AddRange).
or maybe doing it with new instance is fine enough ?