I’m using the following code to randomly instantiate an array of hazards. The array currently consists of 6 hazards. I want to add in one power-up but I only want this to appear in the array once during a round.
Can anyone help?
IEnumerator spawnWaves()
{
inRound = true;
while (true) {
for (int i = 0; i < hazardCount; i++)
{
if (roundEnd == true)
{
inRound = false;
yield return new WaitForSeconds(2);
StartCoroutine("rest1");
yield break;
}
GameObject hazard = hazards[Random.Range(0,hazards.Length)];
Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
Quaternion spawnRotation = Quaternion.identity;
Instantiate(hazard, spawnPosition, spawnRotation);
yield return new WaitForSeconds(Random.Range(spawnWaitMin, spawnWaitMax));
}
yield return new WaitForSeconds(Random.Range(waveWaitMin, waveWaitMax));
}
}