コード例 #1
0
        //Called when the game ends i.e the player loses all their lives
        public void GameOver()
        {
            HighscoresContainer highscoresContainer = FindObjectOfType <HighscoresContainer>();
            BlockOfAliens       blockOfAliens       = FindObjectOfType <BlockOfAliens>();
            FlyingSaucer        flyingSaucer        = FindObjectOfType <FlyingSaucer>();
            int numHighscores = highscoresContainer.GetNumberOfHighScores();
            int lowestScore   = highscoresContainer.GetLowestScore();

            //If there are less than 10 highscores or the player got a score greater than the lowest high score
            //Then the player has just got a highscore so...
            if (numHighscores < 10 || score > lowestScore)
            {
                //Stop the aliens and flying saucer from moving
                blockOfAliens.SetPaused(true);
                flyingSaucer.gameObject.SetActive(false);
                //Make the add score panel active and give the add score script the new score
                addScore.gameObject.SetActive(true);
                addScore.SetScore(score);
            }
            //Else the player didnt get a high score so...
            else
            {
                //Stop the aliens and flying saucer from moving
                blockOfAliens.SetPaused(true);
                flyingSaucer.gameObject.SetActive(false);
                //Display the game over panel
                gameOver.SetActive(true);
            }
            //Pause the game
            Time.timeScale = 0f;
        }
コード例 #2
0
 //Writes the current highscores to the screen, if there are highscores to write
 private void FillTextBoxes()
 {
     if (highscores.GetNumberOfHighScores() != 0)
     {
         //Write the highscores into the textboxes
         List <string> names  = highscores.GetNames();
         List <int>    scores = highscores.GetScores();
         for (int i = 0; i < names.Count; i++)
         {
             namesTextBoxes[i].text = names[i];
             //Format the scores
             scoresTextBoxes[i].text = scores[i].ToString("n0");
         }
     }
 }