- Home /
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.
Answer by Bunny83 · Mar 28, 2015 at 02:03 AM
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.
Still not working! i exactly name the 1 with what my level is actually called, and it still did not work!
Have you tried using the level index? You just say "it doesn't work". What exactly does work, what doesn't? Do you see the Debug.Log message?
If there's no Debug.Log message, your Loading method isn't called at all. Are you sure that script is attached to a script in the scene and the script is enabled? Also make sure the GameObject it's attached to is active. Also keep in $$anonymous$$d if you have set the Time.timeScale to "0" the two seconds will never complete.
Answer by Captain-Awesome · Mar 28, 2015 at 04:05 AM
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. :)
Your answer
Follow this Question
Related Questions
Crosshair changes to opposite colour when hovering over something 1 Answer
[mobile development] 2D Joystick Controller 0 Answers
Menu selection help 1 Answer
'ridgidbody2D' unexpected symbol? Help please. 1 Answer
Variable problem in Javascript. 3 Answers