- Home /
Application.LoadLevel() doesn't clear screen
Hi people! I'm really new on this and I need your help if you can. I'm watching a nice tutorial that teaches me to do a Main Menu. This menu needs to load up another level, but when I do, I keep seeing the buttons I clicked. Menu scene's name is sceneMainMenu.
Thx for helping and sorry for my english. Here is the code.
function OnGUI ()
{
if (GUI.Button(Rect(10,10,100,50),"Start Game"))
{
//print("Starting Game...");
Application.LoadLevel ("sceneLevel1");
}
if (GUI.Button(Rect(10,70,100,50),"Exit Game"))
{
//print("Quitting Game...");
Application.Quit();
}
}
Are any objects in your menu scene marked as DontDestroyOnLoad() ?
http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html
Do you have any errors in the console?
Is your sceneLevel1 added to the build?
Got It. $$anonymous$$y script$$anonymous$$ain$$anonymous$$enu was attached to my camera at sceneLevel1. Noob error. Sorry for opening an answer for that.
Thx for help.
What does your sceneLevel1 contain? Perhaps you have the same onGUI script attached to an object in the scene you're loading?
Also, I removed my mainCamera items from my menus. Apparently my event system or whatnot didn't like that, kept overlaying new scenes over the old ones. added it back in to each menu, tags and all, all good now :)
Answer by JChilton · Jul 25, 2012 at 01:59 AM
The script that is calling OnGUI still exists, and will continue to draw to the GUI.
If there's nothing else in that script that you require, destroy it after it's loaded. Alternatively, if you want to keep the second button (quit), have some boolean check for when to disable the first button.
1:
function OnGUI ()
{
if (GUI.Button(Rect(10,10,100,50),"Start Game"))
{
//print("Starting Game...");
Application.LoadLevel ("sceneLevel1");
Destroy(this);
}
if (GUI.Button(Rect(10,70,100,50),"Exit Game"))
{
//print("Quitting Game...");
Application.Quit();
}
}
or:
//if .cs
bool showStart = true;
//if .js
var showStart = true;
function OnGUI ()
{
if(showStart)if (GUI.Button(Rect(10,10,100,50),"Start Game"))
{
//print("Starting Game...");
Application.LoadLevel ("sceneLevel1");
showStart = false;
}
if (GUI.Button(Rect(10,70,100,50),"Exit Game"))
{
//print("Quitting Game...");
Application.Quit();
}
}
Application.LoadLevel will destroy this object anyway, so it can't be that problem. He answered his own question, the same script was attached to another object in his second scene.