Application.Loadlevel doesn't work even though my level is in Build Settings

Hi there,

I have seen similar problems but I couldn’t find any answer that helped me.
I have a simple menu :

using UnityEngine;
using System.Collections;

public class Menu : MonoBehaviour {
	
	void OnGUI () {
		// Make a background box
		GUI.Box(new Rect(Screen.width / 4f, Screen.height/4, Screen.width /2 , Screen.height / 2), "Loader Menu");
		
		// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
		if(GUI.Button(new Rect(Screen.width / 2.5f, Screen.height/3, Screen.width / 5, Screen.height / 10), "Load Game")) {
			Application.LoadLevel(1);
		}
		
		// Make the second button.
		if(GUI.Button(new Rect(Screen.width / 2.5f, Screen.height/2, Screen.width / 5, Screen.height / 10), "Quit Game"))
		{
			Application.Quit();
		}
	}
}

And I have put my two scenes Menu and Game in Build Settings but still, the scene won’t load after I clicked on it. Anyone knows why ? :slight_smile:

Thanks in advance! ^^

This problem is solved! It actually loaded the scene but I could not see it because of my camera angle, so I didn’t see any change! :wink:

I think you have been struck by the old “1 is not equal to first” problem many new to scripting ends up having!

Application.LoadLevel(1);

Will NOT load the first lvl in your build settings, but the second. I guess since you say nothing happens you probably only have one scene added?

The first scene is 0, the second is 1, the third is 2 etc.
The same goes for lists and every other index in scripting, 0 is always the first entry :wink:

Oh, just for tips you can also load lvl with strings;

Application.LoadLevel("secret_lvl_1337");