So i get an error on path.SetPosition (i, newPos); saying index is out of bounds? I am not sure why or how to solve this. the variable newPos is a vector 3 updated as the game object follows pose. I know its working because instantiate an object when The gameobject pose is moving. I can also print the current vector 3 of the Newpos. so why the error? I just want to build a line render as the object moves to then carry that over to the next scene, but cant get pass this error
Thanks for the help in advance.
private Vector3 lastPos;
private Vector3 newPos;
private bool isMove;
private int i;
private LineRenderer path;
public GameObject wayPoint;
public GameObject pose;
void Start ()
{
i = 0;
path = GetComponent<LineRenderer> ();
StartCoroutine (trackMove ());
}
IEnumerator trackMove()
{
lastPos = pose.transform.position;
yield return new WaitForSeconds (0.5f);
newPos = pose.transform.position;
if (lastPos != newPos) {
Debug.Log ("Im moving");
path.SetVertexCount (i);
path.SetPosition (i, newPos);
i++;
}
else if (lastPos == newPos) {
Debug.Log ("not moving);
isMove = false;
}
StartCoroutine (trackMove ());
}