示例#1
0
    /*
     *  Pacman will lose one life.
     *  If there are more lives to continue, then will update the GUI and
     *  reset all the elements, but the eaten dots and score.
     *  If there are no more lives, then will check if it is a highscore and
     *  then will show the GameOver object and the button to Restart the game.
     */
    private void LoseLife()
    {
        Life -= 1;
        _uiManager.LifesOnGUI(Life);

        if (Life > 0)
        {
            _ghosts.ForEach(ghost => {
                ghost.transform.position = _ghostsHouse.GetPosition2D();
                ghost.gameObject.SetActive(true);
                ghost.Reset();
            });

            _pacman.transform.position = pacmanStarterNode.GetPosition2D();
            _pacman.Reset();

            _gameModeManager.Reset();
        }
        else
        {
            _pacman.gameObject.SetActive(false);

            int highscore = PlayerPrefs.GetInt(settings.HighScoreKeyPlayerPrefs);
            if (Score > highscore)
            {
                PlayerPrefs.SetInt(settings.HighScoreKeyPlayerPrefs, Score);
                _uiManager.HighScoreOnGUI(Score);
            }

            _gameModeManager.GameOver();
        }
    }