I’ve been getting an error message telling me that:
IndexOutOfRangeException: Array index is out of range.
I tried playing with the int variable for Random.Range to get my three spawn points into “range” with nothing working.
The Code:
var spawn : Transform[];
var game_cube : Rigidbody;
var cube_count = 0;
InvokeRepeating("LaunchProjectile", 2, 3);
function Update() {
if (cube_count>= 10) {
CancelInvoke();
}
}
function LaunchProjectile () {
var randomPick : int = Random.Range(0,2);
instance = Instantiate(game_cube, spawn[randomPick].position, transform.rotation);
instance.velocity = Vector3.zero;
cube_count = cube_count +1;
}
Does it have something to do with the “Instantiate” script? Or do I have to attach this directly to the spawn points? The error is telling me there is something wrong with the “instance = Instantiate(game_cube, spawn[randomPick].position, transform.rotation);” line of code. Any ideas?