Menu system: pushing button twice

Hi everyone. I want to make a simple menu system whereby if I push the button once, the menu pops up. If I push it twice, it disappears.

Sounds simple, right? In the pointerdown script associated with the button, I’ve tried assigning a variable to the button state, so that the variable is 0 to start and then 1 after the first push. An if statement is meant to reset the button:
var buttonPushed = 0

If (buttonPushed = 0) {
play the opening menu animation;
set buttonPushed = 1} else {
play the closed animation;
set buttonPushed = 0}

Should work. Doesn’t. Seems to be looping or not responding at all.

Hey,
maybe this will help you: How to add multiple “pointerdown” scripts to one object.
Also your IF statement is wrong. If you use “If (buttonPushed = 0)”, you are assigning to your variable buttonPushed the value of 0 and not comparing it to the value of 0, so instead of “=” try using “==” if you want to check, if the buttonPushed value equals to 0, and “!=” to check if the buttonPushed value not equals to 0. :slight_smile:

Thanks! That’s very helpful.

1 Like