Esempio n. 1
0
    public void Start()
    {
        // checks and saves on collision between checkpoints

        ScoreToSet = PlayerPrefs.GetInt("CheckScore", 0);
        PlayerPrefs.SetInt("score", ScoreToSet);
        PlayerPrefs.Save();

        //saves upon collision wiht checkpoints

        PlayerPrefs.SetInt("CheckPointHit", 0);
        PlayerPrefs.Save();

        // gives player amount of jumps per inputted value

        extraJumps = extraJumpsValue;
        rb         = GetComponent <Rigidbody2D>();

        //finds the tagged object, and turns off collision with player and movinginvwalls

        InvWalls = GameObject.FindGameObjectsWithTag("MovingInvWalls");
        foreach (GameObject InvWall in InvWalls)
        {
            //ignores collision with the invisible walls
            Physics2D.IgnoreCollision(InvWall.GetComponent <Collider2D>(), GetComponent <Collider2D>());
        }
    }
Esempio n. 2
0
    //this is for dealing with the players death
    public void Kill()
    {
        //takes away lives and saves the changes made
        livesObject.LoseLife();

        //taken oout saving of lives as it now serves as a death counter and isnt needed to save between levels
        //livesObject.SaveLives();

        //plays death sound on the kill of player
        Death.Play();

        //checks if its game over
        bool gameOver = livesObject.isGameOver();

        //if lives are = 0 go to game over screen however this will never be called due to lives being converted to a death counter
        if (gameOver == true)
        {
            //if game is over load game over
            SceneManager.LoadScene("Game Over");
        }
        else
        {
            //gets the current scene/level and reloads
            Scene currentLevel = SceneManager.GetActiveScene();
            // if it isnt game over...
            // reset to beginning

            //if the checkpoint isnt made then reset the level, however this doesnt save the scrolls and means that
            //once collected once they are permanently gone until the game fully resets
            if (ifMadeCheckpoint == false)
            {
                SceneManager.LoadScene(currentLevel.buildIndex);
            }
            else
            {
                //checks for boulders & invwalls tagged with other and resets them to their original position within the level
                // this could be reset however i felt that with the death counter
                // a constant resetting of scrolls would be unneccessary and the player could focus on traversing the level as
                //opposed to focusing on score solely

                Boulders = GameObject.FindGameObjectsWithTag("Other");

                foreach (GameObject Boulder in Boulders)
                {
                    Boulder.GetComponent <Boulder_Script>().ResetSelf();
                }

                InvWalls = GameObject.FindGameObjectsWithTag("MovingInvWalls");

                foreach (GameObject InvWall in InvWalls)
                {
                    Physics2D.IgnoreCollision(InvWall.GetComponent <Collider2D>(), GetComponent <Collider2D>());
                    InvWall.GetComponent <InvWalls>().ResetSelf();
                }


                //saves score when the player dies
                ScoreToSet = PlayerPrefs.GetInt("CheckScore", 0);
                PlayerPrefs.SetInt("score", ScoreToSet);
                PlayerPrefs.Save();

                //sets the player position to the last checkpoint with the tag of GM
                gm = GameObject.FindGameObjectWithTag("GM").GetComponent <GameMaster>();
                transform.position = gm.lastCheckPointPos;
            }
        }
    }