- Home /
Start menu gui wont load scene
Hi Guys,
I am really new to Unity3D Free. I have used a load GUI script from Unity's free 'Lerpz Escapes' tutorial and adapted it slightly for my scene. The loading scene comes up nicely with an image i made and the buttons.
When i press 'Start', 'Loading...' pops up, however it doesn't load the scene. I am sure it is some tiny thing i have done incorrectly, but does someone please have an answer for this?
'L4NLevel1' is my scene i want to load, i tryed putting it in the same folder as the 'StartMenuGUI' scene but that doesnt work either.
Code:
#pragma strict
// Make the script also execute in edit mode
@script ExecuteInEditMode()
var gSkin : GUISkin;
var backdrop : Texture2D; // our backdrop image goes in here.
private var isLoading = false; // if true, we'll display the "Loading..." message.
function OnGUI()
{
if (gSkin)
GUI.skin = gSkin;
else
Debug.Log("StartMenuGUI: GUI Skin object missing!");
var backgroundStyle : GUIStyle = new GUIStyle();
backgroundStyle.normal.background = backdrop;
GUI.Label ( Rect( (Screen.width - (Screen.height * 2)) * 0.75, 0, Screen.height * 2,Screen.height), "", backgroundStyle);
//GUI.Label ( Rect( (Screen.width/2)-197, 50, 400, 100), "LEFT4NED","mainMenuTitle");
if (GUI.Button( Rect( (Screen.width/2)-70, Screen.height - 160, 140, 70), "Play"))
{
isLoading = true;
Application.LoadLevel("L4NLevel1"); // load the game level.
}
var isWebPlayer = (Application.platform == RuntimePlatform.OSXWebPlayer ||
Application.platform == RuntimePlatform.WindowsWebPlayer);
if (!isWebPlayer)
{
if (GUI.Button( Rect( (Screen.width/2)-70, Screen.height - 80, 140, 70), "Quit"))
Application.Quit();
}
if (isLoading)
GUI.Label ( Rect( (Screen.width/2)-110, (Screen.height / 2) - 60, 400, 70),"Loading...", "Loading...");
}
Answer by EvilWarren · Oct 31, 2013 at 09:54 AM
Add your scene to File->Build Settings... Scenes In Build.
Awesome! Thanks, i knew it was something simple like this.
Answer by The_Magical_Kiwi · Oct 31, 2013 at 09:49 AM
Are you sure "L4NLevel1" is correct and capilised exactly in that way?
Best thing to do if you are just starting out and trying to debug a piece of code is to use the Debug.Log() method to print stuff to the console.
Try
if (GUI.Button( Rect( (Screen.width/2)-70, Screen.height - 160, 140, 70), "Play"))
{
Debug.Log("I've pressed the button");
isLoading = true;
Application.LoadLevel("L4NLevel1"); // load the game level.
}
That way you'll know you are definitely accessing the block of code which loads the level.
Apart from that it is difficult to suggest answers without more detail.
Thanks for the debug tip, its always useful, and i did see that that particular bit of code was running. I simply didn't add it to the build settings.
Your answer
Follow this Question
Related Questions
Display multiple scenes? 1 Answer
Scene starts before scene loading is finished 0 Answers
[SOLVED]Static Loading screen help 0 Answers
Why do I have to click GUI Menu twice to start in Web player? 0 Answers
What Happens in Scene Load 1 Answer