C# Array Won't Read Length?

Hi, all!

Trying to get a simple movement system going on here. Easy stuff.

Every x seconds a movement occurs based on an Array of Vector 2’s that can be set in the editor.
If the index is out of range, it is set back to zero so that it loops. This repeats forever.

However, I always get an IndexOutofRange exception, and only the first term is ever used, even when the arrays have 3+ terms! I don’t know what is going wrong here and would really appreciate some help.

Thanks!- YA

using UnityEngine;
using System.Collections;

public class Fall : MonoBehaviour {
	static bool move = true;
	public float myTime;
	public Vector2[] myJump;
	// Use this for initialization
	void Start () {
		StartCoroutine ( Move ( myTime, myJump ) );
	}
	
	// Update is called once per frame
	IEnumerator Move( float myTime, Vector2[] myJump ){
		while( true ){
			int index = 0;
			yield return new WaitForSeconds( myTime );
			if( move ){ 
				Vector2 thisMove = myJump[index];
				transform.Translate( thisMove );
				if( index >= myJump.Length - 1) index = 0;
				index += 1;
			}
			else return false;
		}
	}
}

Not sure where the IndexOutOfRange is coming from, but you need to move the declaration of index out of the while loop. Right now it’s initialized back to 0 at the top of the loop every time. If the index out of range is from line 19, then it must mean that in some cases myJump has no entries in it. You certainly aren’t checking for that case, but should if you want to code to be bullet proof.