Author Topic: Same user input to show and hide a panel?  (Read 3410 times)

Seith

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 37
    • View Profile
    • SeithCG
Same user input to show and hide a panel?
« on: January 30, 2014, 09:10:49 AM »
Hello, I have a very basic question: Pressing the "B" button on the gamepad activates a panel in which lies a UIButton. But this UIButton's action is to close the panel when it is clicked. So when I press "B" on the gamepad the panel shows up (just the alpha toggling to 1) but as soon as I release the button the panel of course hides itself (alpha back to 0) because the UIButton does its job.

It's a typical case of the snake eating its own tail. What would be the proper way to achieve this simple behavior (same user input to show and hide a panel)? Thanks...
SeithCG.com

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Same user input to show and hide a panel?
« Reply #1 on: January 30, 2014, 11:24:46 AM »
Do you select the button? It shouldn't get input unless it's selected. You can always delay an operation until the end of frame by using a coroutine.

Seith

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 37
    • View Profile
    • SeithCG
Re: Same user input to show and hide a panel?
« Reply #2 on: January 30, 2014, 12:48:55 PM »
The thing is the button (being the only button) is selected by default it seems.

So what I did is disabling the UIButton component by default. Then I added an Update function to track when the interaction button is NOT pressed and if the alpha of the panel is 1 (meaning the panel is visible) then I enable the UIButton component. That way the button does not register a press as soon as the panel is visible.

If the panel itself were properly disabled to begin with, and then enabled would the UIButton also catch the button pressing right away? Maybe I should try that...
SeithCG.com