GUI and changing scenes

How do i make a GUI button that changes scenes when clicked
It should be relatively easy but i’m doing it in c# script and i am having problems .

if(GUI.Button(new Rect(10, 10, 100, 100), “Change Scene”))
Application.LoadLevel(1);

Extending @Meltdown’s answer, Application.LoadLevel() has to be configured before use.

Configure your scenes to be included in Build at File > Build Settings; after you click “Add Current Scene” button, the current editing scene will be added to Scene List, with a number (which is the index of the scene) on the right.

Then, you can call the scene by:

Application.LoadLevel(1); // the scene with index = 1

or

Application.LoadLevel("YourNextScene"); 
// if your scene file name is YourNextScene.unity

On the other hand, by calling the above function, Application.loadedLevel & Application.loadedLevelName will be updated.

Reference: Applicaiton.LoadLevel

Note: There are few more associated functions:

thank you very much :slight_smile: