Author Topic: How to detect when un press a button ?  (Read 6247 times)

tnbao91original

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 41
    • View Profile
How to detect when un press a button ?
« on: June 04, 2014, 03:01:27 AM »
OnPress method only run 2 time when i press and unpress a button. I put a log in OnPress method and it show me 2 time but how can i detect when i unpress ? Any method OnUnPress ?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: How to detect when un press a button ?
« Reply #1 on: June 04, 2014, 05:14:12 AM »
OnPress has a bool as parameter.

  1. void OnPress(bool pressed)
  2. {
  3. if (pressed){
  4. Debug.Log("You pressed down on "  + gameobject.name, gameobject)
  5. }
  6. else{
  7. Debug.Log("You released on "  + gameobject.name, gameobject)
  8. }
  9. }

tnbao91original

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 41
    • View Profile
Re: How to detect when un press a button ?
« Reply #2 on: June 04, 2014, 10:30:09 AM »
Solved, thank you for support :)

Darkmax

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 93
    • View Profile
Re: How to detect when un press a button ?
« Reply #3 on: June 04, 2014, 12:57:42 PM »
Also you can use OnClick() method this is called when your button is released