/** * Coroutine for spawning asteroids. */ private IEnumerator SpawnAsteroidsCoroutine() { yield return(new WaitForSeconds(spawnBeginningWait)); while (continueSpawningAsteroids) { if (!recalculationFinished) { yield return(new WaitForSeconds(0.5f)); continue; } //Chose an amount of asteroids to spawn at a time int numAsteroidsToSpawn = Random.Range(1, maxAsteroidsSpawnAtTime); for (int index = 0; index < numAsteroidsToSpawn; index++) { //Spawn asteroid GameObject spawnedEnemy = SpawnInWave(asteroidClass.NextObject(), asteroidMaterials); spawnedEnemy.GetComponent <ObjectStraightMover>().speed = asteroidSpeed; yield return(null); } //Wait for new asteroid to create yield return(new WaitForSeconds(asteroidClass.NextWaitTime())); } }
/** * Coroutine for spawning powerups */ private IEnumerator SpawnPowerupsCoroutine() { yield return(new WaitForSeconds(powerupClass.NextWaitTime())); while (numEnemiesLeft > 0) { if (!recalculationFinished) { yield return(new WaitForSeconds(0.5f)); continue; } //Only spawn one powerup at a time GameObject powerupToSpawn = powerupClass.NextObject(); yield return(null); //Spawn powerup SpawnInWave(powerupToSpawn); yield return(new WaitForSeconds(powerupClass.NextWaitTime())); } }
private IEnumerator SpawnEnemiesCoroutine() { yield return(new WaitForSeconds(spawnBeginningWait)); while (numEnemiesLeft > 0) { if (!recalculationFinished) { yield return(new WaitForSeconds(0.5f)); continue; } //Chose an amount of enemies to spawn at a time int numEnemiesToSpawn = (int)Random.Range(1, maxEnemiesSpawnAtTime); for (int index = 0; index < numEnemiesToSpawn; index++) { //Choose enemy to spawn GameObject enemyToSpawn = enemyClass.NextObject(); yield return(null); //Spawn enemy GameObject newEnemy = SpawnInWave(enemyToSpawn); numEnemiesLeft--; yield return(null); //Set different enemy guns if alien if (newEnemy.CompareTag("Alien")) { AIWeapons weapons = newEnemy.GetComponent <AIWeapons>(); GunDefinition[] guns = null; if (weapons != null) { guns = weapons.guns; } else { weapons = newEnemy.GetComponentInChildren <AIWeapons>(); guns = weapons.guns; } //TODO: correct implementation for (int gunIndex = 0; gunIndex < guns.Length; gunIndex++) { //Choose random gun GameObject gunToSet = enemyWeaponClass.NextObject(); yield return(null); guns[gunIndex].ChangeWeapon(gunToSet); yield return(null); } } yield return(new WaitForSeconds(enemyClass.NextWaitTime())); //pause } } //advance when no more enemies exist continueSpawningAsteroids = false; yield return(new WaitForSeconds(5)); manager.AdvanceLevel(); }