示例#1
0
 IEnumerator waveSequence(bool showText)           //Used for defined waves
 {
     wavesScript.SpawnWave(sequence[waveCounter]); //first wave
     if (showText)
     {
         alertText.text = "Wave 1";
         StartCoroutine(clearAlertOnDelay(3));
     }
     waveCounter = 0;
     while (waveCounter <= sequence.Count && GameControl.alive == true)
     {
         if (wavesScript.CheckIfWaveComplete())
         {
             waveCounter++;
         }
         if (waveCounter == sequence.Count)//If the last wave ended
         {
             alertText.color = Color.green;
             alertText.text  = "You Win!";                                                             //Displays victory message
             alertText.transform.position = new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 0); //Centers the win text
             StartCoroutine(endGameOnDelay(3));
             waveCounter++;                                                                            //Ends coroutine and prevents infinite loop
         }
         else
         {
             if (wavesScript.CheckIfWaveComplete())
             {
                 StartCoroutine(nextWaveOnDelay(2));
                 if (showText)
                 {
                     alertText.text = "Wave " + (waveCounter + 1);
                     StartCoroutine(clearAlertOnDelay(2));
                 }
                 yield return(new WaitForSeconds(3));
             }
             else
             {
                 yield return(new WaitForSeconds(2));//Checks if the wave is complete every 4 seconds
             }
         }
     }
 }