Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IEnumerator SpawnWaves()
- {
- yield return new WaitForSeconds(startWait);
- while (true) {
- if (waves < waveCount && !gameOver)
- {
- for (int i = 0; i < hazardCount; i++)
- {
- //pick a random enemy from array
- GameObject hazard = hazards[Random.Range(0, hazards.Length)];
- Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
- Quaternion spawnRotaion = Quaternion.identity;
- Instantiate(hazard, spawnPosition, spawnRotaion);
- yield return new WaitForSeconds(spawnWait);//how long until next enemy is spawned
- }
- }
- if (!gameOver && !bossDead)
- {
- waves++;
- Debug.Log("Wave(s): " + waves);
- yield return new WaitForSeconds(waveWait);//how long until next wave is spawned
- }
- if (waves == waveCount && !gameOver)
- {
- //change to the boss music
- AudioSource audio = GetComponent<AudioSource>();
- audio.clip = bossMusic;
- audio.Play();
- //spawn the boss
- Vector3 bossSpawnPositon = new Vector3(0f, 0f, 20f);
- Quaternion spawnRotaion = Quaternion.identity;
- Instantiate(boss,bossSpawnPositon,spawnRotaion);
- Debug.Log("Boss spawned");
- }
- if (waves >= waveCount && !gameOver && GameObject.FindWithTag("Enemy") == null && !bossDead)
- {
- bossDead = true;
- //change to the boss killed music
- AudioSource audio = GetComponent<AudioSource>();
- audio.clip = bossKilled;
- audio.Play();
- yield return new WaitForSeconds(3f);
- audio.clip = scoreMusic;
- audio.Play();
- }
- if (gameOver)
- {
- yield return new WaitForSeconds(2f);
- restartText.text = "Press 'Fire' for restart";
- restart = true;
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment