- Home /
Question by
CB-TV · May 22, 2014 at 04:17 PM ·
guitextureif statementgui.buttonstatic-vars
GUI.Button is always true?
A variable inside a GUI.Button if statement changes to true when I start my game without the button being pressed. I am sure that this is the button that is doing this because I have checked and anything inside it activates. I'll give you my script and any info would be appreciated!
var texture : Texture;
static var started = false;
function OnGUI ()
{
if (!started)
{
if (GUI.Button (Rect (450, 300, 100, 100), texture));
{
started = true;
}
}
}
function Update ()
{
print (started);
if (started)
{
gameObject.Find ("Image").SetActive (false);
}
}
When the game starts up, started is true but then goes to false the next frame without me pressing the button. GUI.Button works fine in another script I made, it's really weird!
Comment
When does started go to false? Nothing in the code you've posted does that.
Best Answer
Answer by robertbu · May 22, 2014 at 05:02 PM
Remove the ';' at the end of line 9. You are terminating your 'if' statment with it.