Path finding script

Hi There :wink:

Im using pretty useful stuff, found here:

http://forum.unity3d.com/threads/60137-my-AI-target-path-script-(update-youtube-video-demo)

but… it doesnt work to me:

IndexOutOfRangeException: Array index is out of range.
Script3.Update () (at Assets/Script3.js:8)

IndexOutOfRangeException: Array index is out of range.
Script3.Update () (at Assets/Script3.js:39)

but is should work… and I cant get why path[0] has no value (maybe thats why its out of range) ?

edit: key is always 0…

Have you set up the path variable in the inspector correctly? You need to set the array’s size variable to the number of points you want on the path. Then, you need to go through the points in the array and set the coordinates. A useful technique when doing things like this is to add a Gizmo script to your file to let you see the path joined up by lines in the scene view:-

function OnDrawGizmos() {
	if (path.Length == 0)
		return;
		
	var prevPt = path[0];
	
	for (i = 1; i < path.Length; i++) {
		var currPt = path[i];
		Gizmos.DrawLine(prevPt, currPt);
		prevPt = currPt;
	}
}