hello, I get an index out of range exception ,
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
on this line (line 59) in snippet
PhotonNetwork.InstantiateRoomObject(zombiePrefabs[zombie].prefab.name, allSpawns[tempspawn[spawn]].transform.position, allSpawns[tempspawn[spawn]].transform.rotation, 0, instData);
any input would be appreciated!
if (defineSpawn == true)
{
//for loop to spawn the amount of zombies.
for (int i = 0; i < toSpawn; i++)
{
if (zombiePrefabs.Length > 0)
{
var tempspawn = new List<int>();
//get random zombies id from avail zombie prefabs.
int zombie = Random.Range(0, zombiePrefabs.Length);
int globalZombie = System.Array.IndexOf(zws.zombiePrefabs, zombiePrefabs[Random.Range(0, zombiePrefabs.Length)]);
int spawn = 0;
//if spawnIndex not set, spawn like the old version
if (zws.zombiePrefabs[globalZombie].spawnIndex.Length > 0)
{
//put all possible spawner for given zombie into a list.
for (int x = 0; x < allSpawns.Length; x++)
{
if (!allSpawns[x].lockedToArea || allSpawns[x].lockedToArea.isUnlocked)
{
if (zws.zombiePrefabs[globalZombie].spawnIndex.Contains(x))
{
tempspawn.Add(x);
}
}
}
//pick a random spawn to spawn that zombie.
spawn = Random.Range(0, tempspawn.Count);
int skin = Random.Range(0, zombiePrefabs[zombie].skins.Length);
object[] instData = new object[2];
instData[0] = globalZombie;
instData[1] = skin;
//Debug.Log("zombie name: "+ zombiePrefabs[zombie].skins[skin].name + "spawned location" + allSpawns[tempspawn[spawn]].name);
PhotonNetwork.InstantiateRoomObject(zombiePrefabs[zombie].prefab.name, allSpawns[tempspawn[spawn]].transform.position, allSpawns[tempspawn[spawn]].transform.rotation, 0, instData);
}
//this is old version code.
else
{
spawn = Random.Range(0, useableSpawns.Length);
int skin = Random.Range(0, zombiePrefabs[zombie].skins.Length);
object[] instData = new object[2];
instData[0] = globalZombie;
instData[1] = skin;
//Debug.Log("zombie name: " + zombiePrefabs[zombie].skins[skin].name + "spawned location:" + useableSpawns[spawn].name);
PhotonNetwork.InstantiateRoomObject(zombiePrefabs[zombie].prefab.name, useableSpawns[spawn].transform.position, useableSpawns[spawn].transform.rotation, 0, instData);
}
}
else
{
Debug.LogError("No Zombie Prefabs found");
}
}
}