コード例 #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        // Detects if the object/assets that was collided with holds the "Enemy" script
        if (collision.collider.GetComponent <Enemy>())
        {
            //Take away a life and save that change
            livesObject.LoseLife();
            livesObject.saveLives();

            //Plays the death sound
            Death.Play();

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

            if (gameOver == true)
            {
                //If it IS game over, load the game over scene
                SceneManager.LoadScene("Game_Over");
            }

            else
            {
                //Detects what the current score of the player is
                Score.scoreValue = PlayerPrefs.GetInt("score", 0);

                //Detects what level the player is on and saves it
                Scene currentLevel = SceneManager.GetActiveScene();

                //Relods the saved level, from the start point of that level
                //using the build index
                SceneManager.LoadScene(currentLevel.buildIndex);
            }
        }
    }
コード例 #2
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's game over
        bool gameOver = livesObject.IsGameOver();

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

        else
        {
            // 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);
        }
    }
コード例 #3
0
    public void Kill()
    {
        // Take away a life and save that change
        LivesObject.LoseLife();
        LivesObject.SaveLives();

        //Check if it's game over
        bool gameOver = LivesObject.IsGameOver();

        if (gameOver == true)
        {
            // If it IS game over...
            // Load the game over screen
            SceneManager.LoadScene("GameOver");
        }
        else
        {
            // If it is NOT game over...
            // Reset the current level to restart from the beginning


            //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 level again
            //by passing the build index of our level
            SceneManager.LoadScene(currentLevel.buildIndex);

            // Death sound play when player is killed
            Death.Play();
        }
    }
コード例 #4
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 game over
        bool gameOver = livesObject.IsGameOver();

        if (gameOver == true)
        {
            //if is game over load game over scene
            SceneManager.LoadScene("GameOver");
        }
        else
        {
            //if not game over reset current level from start

            //reset the current level to restart from beginning

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

            //second tell Unity to load current level again
            //by passing the build index of our level
            SceneManager.LoadScene(currentLevel.buildIndex);
        }
    }
コード例 #5
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);
        }
    }
コード例 #6
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        // Check the thing we bump into is an enemy
        if (collision.collider.GetComponent <Enemy>())
        {
            //Take away a life and save that change
            livesObject.LoseLife();
            livesObject.saveLives();



            //Check if its game over

            bool gameOver = livesObject.IsGameOver();

            if (gameOver == true)
            {
                //If it IS game over...
                //Load the game over scene

                SceneManager.LoadScene("Game_Over");
            }

            else
            {
                //try and fix this you need to try and get the game to take away a life but not reset
                //but still check to see if the gme is over and the get the game to reset


                //If it is NOT game over...
                //reset the current level to restart from the begining

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

                //First, ask untiy what the current level is

                Score.scoreValue = PlayerPrefs.GetInt("score", 0);


                Scene currentLevel = SceneManager.GetActiveScene();

                //Second, tell unity to load the current again
                // by passing the build index of our level


                SceneManager.LoadScene(currentLevel.buildIndex);
            }
        }
    }
コード例 #7
0
ファイル: Death.cs プロジェクト: MrSleazy/COMP376A2
    public void Die()
    {
        if (!isReviving)
        {
            isDying = true;
            lives.RemoveLife();
            player.DisableControls();
            player.DisableWrapAround();
            player.DisableCollisions();

            if (lives.IsGameOver())
            {
                Application.LoadLevel("GameOver");
            }
        }
        else
        {
            Debug.Log("Invincible frames!");
        }
    }
コード例 #8
0
ファイル: Fletcher.cs プロジェクト: MHadley98/FletchQuest
    public void Kill()
    {
        livesObject.LoseLife();
        livesObject.SaveLives();

        //check to see if any lives left
        bool gameOver = livesObject.IsGameOver();

        if (gameOver == true)
        {
            //loads Game Over is no lives left
            SceneManager.LoadScene("GameOver");
        }

        else
        {
            //gets and reloads current level
            Scene currentLevel = SceneManager.GetActiveScene();

            SceneManager.LoadScene(currentLevel.buildIndex);
        }
    }
コード例 #9
0
    //Our own fuction for handling player death
    public void Kill()
    {
        lives.LoseLife();

        lives.SaveLives();

        if (lives.IsGameOver())
        {
            // Go to game over screen
            SceneManager.LoadScene("GameOver");
        }
        else
        {
            //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 level again.
            //By passing the build index of our level
            SceneManager.LoadScene(currentLevel.buildIndex);
        }
    }