calling random numbers repeatedly with random.Range
i want my villains to appear from multiple directions and I am using random.Range to select the spawn spots. when i try to set the variable to a new random number, unity just hangs and does not spawn. can anyone explain what is happening here? thanks.
else if (waveCounter == 6)
{
int randSpot = Random.Range(0,13);
Instantiate (LvlTwoVillain, spawnSpots[randSpot].position, spawnSpots[randSpot].rotation );
yield return new WaitForSeconds (spawnWait);
randSpot = Random.Range(0,13);
Instantiate (LvlOneVillain, spawnSpots[randSpot].position, spawnSpots[randSpot].rotation );
yield return new WaitForSeconds (spawnWait);
}
How long is your spawnWait? If its too long, it might be causing the hanging
Answer by bstout · Oct 26, 2016 at 07:40 PM
the spawn wait was 5 seconds.
if i comment out the " randSpot = Random.Range(0,13);" on the second iteration, unity doesn't hang. so it seems to be that line. also when i comment it out, the lvlOneVillain often appears in a different place. so it appears that each instantion calling on randSpot will generate a new number on it's own since the two villains appear in different places.
i am now thinking the hang is from incorrectly decrementing villains as i added the lvlToVillians.