Loadlevel when you press a key?

Hello everybody,

I can’t seem to figure out how to load a scene when I press a key. I’ve been trying to look up scripts, write scripts, and find help but I just can’t seem to do it. Even if I do have the right script, I’m sure what to attach it to. If anyone could help me out with this problem, I would seriously appreciate it! Thank you so much!

This is the script you’re after. Your script should look something like this:

void Update ()
{
	if (Input.GetButtonDown(KeyCode.Enter))
	{
		Application.LoadLevel();
	}
}

Well it doesn’t really matter what your script is attached to, but if you use

Application.LoadLevel("yourscene") //or index number

It will load the scene whenever it gets called. You first have to make sure the scene you’re trying to load is in the list of scenes in your build settings though, which is also how you can find the index number of each scene. You probably already know how to write an if statement for input so I’ll leave it at that, but if you have any questions or I misinterpreted your question feel free to ask

Create a script with this update function:

void Update()
{
    if(Input.GetKeyDown("x"))
    {
        Application.LoadLevel("scene name");
    }
}

Also make sure to open File > Build Settings, and add the scene you want to load to “scenes to build”. You can add this script to any object in your scene. I would just put it on the main camera.