Question by
Beta4 · Feb 14, 2018 at 11:31 PM ·
restart game
Restarting 2D Rouge Like Game Tutorial with "R" keyboard press
How would I go about adding a "R" button press to restart the 2D Rouge Like Tutorial game once your character dies.
Comment
Answer by Pandaa2610 · Feb 19, 2018 at 10:02 AM
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadScene : MonoBehaviour
{
private bool playerIsDead;
void Update(){
if (playerIsDead == true){
if (Input.GetKeyDown("KeyCode.R")){
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
}
}
Now you only have to set the bool playerIsDead to true if he dies.
Answer by Beta4 · Feb 19, 2018 at 10:48 PM
Thank you I will certainly give that a try when I get home. Thank you for your input.
Your answer
Follow this Question
Related Questions
Restart not working. 0 Answers
I got a bunch of problems and i don't know how to fix them! 0 Answers
How to make a button appear with a condition? 1 Answer
Scenes don't repeat themselves after pressing a restart button 1 Answer
One question... 0 Answers