- Home /
Question by
ashjack · Oct 13, 2013 at 07:23 PM ·
javascriptguigameobjecttoggleactive
Trouble getting GUI phone to open/close
I am making a GUI mobile phone for my game, and I am having trouble getting it to work. It does not close. Here is my code:
var onoff : boolean;
var testObject : GameObject;
function Update () {
if (Input.GetKeyDown(KeyCode.P)&&onoff == true)
testObject.active = false; onoff = false;
if (Input.GetKeyDown(KeyCode.P)&&onoff == false)
testObject.active = true; onoff = true;
}
Comment
You if statements are un-braced which means the if will execute the next statement only.
If you are trying to include onoff = false; in your if statement, add braces.
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.P)&&onoff == true)
{
testObject.active = false; onoff = false;
}
You should also specify onoff = false in the declaration.
Best Answer
Answer by ashjack · Oct 13, 2013 at 09:02 PM
Thanks! I added the brackets, and it still didn't work, but I changed the second if to else if and it worked. I tested it without the brackets and it did not work. So thanks for fixing the brackets for me.