- Home /
GUI.Button gets clicked automatically
Hey, i am trying to make a simple LevelLoader
#pragma strict
var loadLevel : boolean = false;
var levelSelector : int = 0;
function Start () {
}
function Update () {
if(loadLevel == true)
{
Application.LoadLevel(1);
}
}
function OnGUI()
{
if(GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 50),"Start the game!") /* && Input.GetMouseButtonDown(0) */);
{
loadLevel = true;
}
}
This is what the code looks like, so far no problems. But when i start the game the button gets clicked without me even touching it and sets the boolean to = true before you even have a chance to get ready. The only reason the boolean is there is because i tried to solve this problem. When i just wrote the GUI.Button and Applicaton.LoadLevel(1) the same thing happened. Unity bug, or have i missed something?
How about when i click into the scene will click it again automatic without touching any device or pc
Answer by Radivarig · Apr 10, 2014 at 02:17 AM
Remove semicolon ';' from the end of line 21, with that semicolon your if statement has nothing to do and loadLevel = true;
is executed every OnGUI call.
Radivarig
Oh wow, guess this is just another proof that you shouldnt be coding while tired. Thank you so much hehe!
Your answer
Follow this Question
Related Questions
GUI Button Disappearing 1 Answer
I have doubt please help me 2 Answers
Javascript GUI.Button help, Error BCE0077 1 Answer