FYI: I am newish to Unity
I found a bit of code on the internet and tweaked it a little bit. To me, everything looks like it should be working, but I keep receiving an ‘IndexOutOfRangeException: Array index is out of range’.
After assigning the script, I set the size to 7 and then attach my prefabs respectively.
What am I overlooking to keep receiving this error message?
#pragma strict
var spawnObjects : GameObject[];
var newSpawn : Transform;
function Start ()
{
//initialize spawning points array
spawnObjects = GameObject.FindGameObjectsWithTag("Respawn");
}
// Starting in 0.5 seconds, a projectile will be launched every 0.3 seconds
InvokeRepeating("LaunchProjectile", 0.5, 0.3);
function LaunchProjectile ()
{
//randomly return position of a spawn point
var spawnPos = spawnObjects[(Random.Range(0, spawnObjects.length))].transform.position;
Instantiate(newSpawn, spawnPos, Quaternion.identity);
}