spoon420

Untitled

Mar 25th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 KB | None | 0 0
  1.  IEnumerator SpawnWaves()
  2.     {
  3.         yield return new WaitForSeconds(startWait);
  4.         while (true) {
  5.             if (waves < waveCount && !gameOver)
  6.             {
  7.                 for (int i = 0; i < hazardCount; i++)
  8.                 {
  9.                     //pick a random enemy from array
  10.                     GameObject hazard = hazards[Random.Range(0, hazards.Length)];
  11.                     Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
  12.                     Quaternion spawnRotaion = Quaternion.identity;
  13.                     Instantiate(hazard, spawnPosition, spawnRotaion);
  14.                     yield return new WaitForSeconds(spawnWait);//how long until next enemy is spawned
  15.                 }
  16.             }
  17.  
  18.             if (!gameOver && !bossDead)
  19.             {
  20.                 waves++;
  21.                 Debug.Log("Wave(s): " + waves);
  22.                 yield return new WaitForSeconds(waveWait);//how long until next wave is spawned
  23.             }
  24.  
  25.            if (waves == waveCount && !gameOver)
  26.             {
  27.                 //change to the boss music
  28.                 AudioSource audio = GetComponent<AudioSource>();
  29.                 audio.clip = bossMusic;
  30.                 audio.Play();
  31.  
  32.                 //spawn the boss
  33.                 Vector3 bossSpawnPositon = new Vector3(0f, 0f, 20f);
  34.                 Quaternion spawnRotaion = Quaternion.identity;
  35.                 Instantiate(boss,bossSpawnPositon,spawnRotaion);
  36.                 Debug.Log("Boss spawned");
  37.             }
  38.  
  39.             if (waves >= waveCount && !gameOver && GameObject.FindWithTag("Enemy") == null && !bossDead)
  40.             {
  41.                 bossDead = true;
  42.  
  43.                 //change to the boss killed music
  44.                 AudioSource audio = GetComponent<AudioSource>();
  45.                 audio.clip = bossKilled;
  46.                 audio.Play();
  47.                 yield return new WaitForSeconds(3f);
  48.                 audio.clip = scoreMusic;
  49.                 audio.Play();
  50.             }
  51.  
  52.  
  53.             if (gameOver)
  54.             {
  55.                 yield return new WaitForSeconds(2f);
  56.                 restartText.text = "Press 'Fire' for restart";
  57.                 restart = true;
  58.                 break;
  59.             }
  60.         }
  61.     }
Add Comment
Please, Sign In to add comment