Exemplo n.º 1
0
    // Our own function for handling player death
    public void Kill()
    {
        // take away a life and save that change
        livesObject.Loselife();
        livesObject.Savelives();

        // check if it is game over then
        bool gameOver = livesObject.IsGameOver();

        if (gameOver == true)
        {
            // if it is game over...
            // load the game over scene
            SceneManager.LoadScene("GameOver");
        }
        else
        {
            // if it is game over...
            // load the game over scene

            // if it is not game over
            // reset the current level to restart from screen

            // Reset the current level to restart from the beginning.

            // First, ask unity what the current level is
            Scene currentLevel = SceneManager.GetActiveScene();

            // Second, tell unity to load the current again
            // by passing the build index of our level
            SceneManager.LoadScene(currentLevel.buildIndex);
        }
    }
Exemplo n.º 2
0
    //our own function for handling player death
    public void Kill()
    {
        //take away life and save that change
        livesObject.Loselife();
        livesObject.SaveLives();

        Death.Play();

        //check if its game over
        bool gameOver = livesObject.IsGameOver();

        if (gameOver == true)
        {
            //if is.............load game over scene
            SceneManager.LoadScene("GameOver");
        }
        else
        {
            //if no..............
            //Reset current level to restart from beginning
            //first ask unity what current level is
            Scene currentLevel = SceneManager.GetActiveScene();

            //second, tell unity to load current level again, by passing build index of our level
            SceneManager.LoadScene(currentLevel.buildIndex);
        }
    }