- Home /
Loadlevel and buttons...
I've made a menu system that uses "Application.Loadlevel();" in order to load my scenes. When I go to build and play my game, the button I have set up to load the "Credits" works fine but the button that starts the first level doesn't work at all. What am I missing? Does the way the level is named important? What if you renamed a level after you add it to the "Scenes to build" window, will it still work properly?
My Code:
var mySkin : GUISkin;
function OnGUI () {
GUI.skin = mySkin;
GUI.Box(Rect(0, 0, Screen.width, Screen.height), "");
if (GUI.Button (Rect (180,400,300,250), "Start")) {
Application.Loadlevel("Level1");
}
if (GUI.Button (Rect (520,400,300,250), "Quit")) {
Application.LoadLevel("Credits");
}
}
Rena$$anonymous$$g a level it's not important (will appear automatically renamed in "Scenes to build" (containing, as better list to test in your case: 0 = "Level1"; 1 = "Credits"). - It's there any errors in debug window when you press Play to play "Level1" scene? - Which object have attached above script, and in which scene ("Level1" or "Credits")? As dannyskim said, your script looks good, but I think we need more details about how the script it's used.
I have my menu script on a GUITexture, and its in level zero
I went back and found this error: "$$anonymous$$issing$$anonymous$$ethodException: $$anonymous$$ethod not found: 'UnityEngine.Application.Loadlevel'.
Answer by GameGuy · Dec 06, 2011 at 01:15 AM
Your spelling is incorrect.
You wrote "Application.Loadlevel" , but it should be "Application.LoadLevel"
Edit: Look at the L in Level(Application.LoadLevel) it is lower case and should be upper case! :)
Answer by dannyskim · Dec 05, 2011 at 07:38 PM
Doesn't look like there is anything wrong with your code. Have you checked your Build Settings:
File => Build Settings...
and made sure that all your scenes are loaded into the 'Scenes to Build' window? Have you double checked your spelling, because as I'm sure you know passing strings inside of functions is explicitly case sensitive?
I have the level in the scene to build and the name is spelled the same way as in the script and it still doesn't work. I even tried loading the level by index.
I dont know why my answer is ignored, and yours is upvoted but the problem here is not File => Build Settings or anything else. It is a simple spelling mistake!