//this is for dealing with the players death public void Kill() { //takes away lives and saves the changes made livesObject.LoseLife(); livesObject.SaveLives(); //checks if its game over bool gameOver = livesObject.isGameOver(); if (gameOver == true) { //if game is over load game over SceneManager.LoadScene("GameOver"); } else { // if it isnt game over... // reset to beginning //check current level Scene currentLevel = SceneManager.GetActiveScene(); //second tell unity to reload level SceneManager.LoadScene(currentLevel.buildIndex); } }
//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; } } }