How can I make the level restart when someone presses R

Okay, so in my game if you fall out of the world, you continue to fall for ever, I want to make it so you can press R when you fall out to restart something that triggers Application.LoadLeve(1); Ive googled all over the place for this answer could not find it how would I make it detect a keyboard press?

You will do something like:

void Update()
{
    if(Input.GetKeyDown(KeyCode.R))
        Application.LoadLevel(0); //or whatever number your scene is

}

More info on the GetKeyDown method can be found here: Unity - Scripting API: Input.GetKeyDown

Hey,

check this.

Zotey

This is how the code should look like. (maybe with a little “R” in Restart to make it work with your script, but should have been with a capital one) :wink:

public class Restart : MonoBehaviour{
	void Update(){
		if(Input.GetKeyDown(KeyCode.R)){
			Application.LoadLevel(1); 
		}
	}
}

Maybe you should read some more about basic scripting: Learn game development w/ Unity | Courses & tutorials in game design, VR, AR, & Real-time 3D | Unity Learn