H4rry
1
hi guys i have been trying to finish space shooter tutorial but i got stuck at this part where i need to spawn waves i don’t what to do to make the following function starts a decent number of asteroids and keeps on going on its own :
function SpawnWaves () {
while (true) {
yield WaitForSeconds (2);
var spawnPosition : Vector3= new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
var spawnRotation : Quaternion= Quaternion.identity;
Instantiate (hazard, spawnPosition, spawnRotation);
}
Kiwasi
2
What you want is something like this
function SpawnWaves () {
// set up the initial spawn, I have 5, but you can change this
for(var i : int = 0; i < 5; i++) {
SpawnOneWave();
}
while (true) {
yield WaitForSeconds (2);
SpawnOneWave();
}
}
function SpawnOne Wave () {
var spawnPosition : Vector3= new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
var spawnRotation : Quaternion= Quaternion.identity;
Instantiate (hazard, spawnPosition, spawnRotation);
}