Application.Loadlevel NOT WORKING!

My code:

#pragma strict
 var LoadingSign : Texture2D;
 
 function Start()
 {
     Invoke("Loading", 2);
 }
 
 function Loading()
 {
     Debug.Log("The level should have loaded now.");
     Application.LoadLevel("1");
     }    
 function OnGUI(){
  theGUILoad();
 }
 
 function theGUILoad(){
  GUI.Label(Rect(450, 150, 400, 500), LoadingSign);
 }

There are no errors on this one, just not loading level, I even added the debug.log, and nothing still.

Is your level named “1”? If you ment using the level index you should use an integer value:

Application.LoadLevel(1);

The string version of Application.LoadLevel expects the file name of the level. Example:

Application.LoadLevel("MyLevelName");

Keep in mind that you can only load levels that are added in the build settings dialog.

Also note that the index starts at 0. So check your levels in your build settings dialog. The level index can be found at the far right of each level.

Bunny83’s answer should have worked.

Did you add the level to load to your “scenes to build”? I don’t think you can load levels unless they’re in that list.

From the File menu, choose Build Settings. Then drag your level to the “Scenes to Build” list, and then try Application.LoadLevel(0);

Do that and it’s guaranteed to load something. :slight_smile: