Author Topic: Button (finger on button action) like touch.stationary how ?  (Read 4205 times)

hotshots

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
when finger on button must do something. not only one click. how to make it ?  i mean like touch.stationary

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Button (finger on button action) like touch.stationary how ?
« Reply #1 on: June 04, 2014, 12:45:22 AM »
  1. bool mIsPressed = false;
  2.  
  3. void OnPress (bool isPressed) { mIsPressed = isPressed; }
  4.  
  5. void Update ()
  6. {
  7.     if (mIsPressed) Debug.Log("Do something");
  8. }

Daemon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Button (finger on button action) like touch.stationary how ?
« Reply #2 on: June 30, 2014, 02:40:28 PM »
Hi ArenMook,

Could you explain your code a bit more ? May be I'm not so experience but I don't understand what does it mean ? I need to solve the same problem as Hotshots I need something as  touch.stationary. Thank you for your reply.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Button (finger on button action) like touch.stationary how ?
« Reply #3 on: June 30, 2014, 07:21:30 PM »
OnPress(bool pressed) is called by the NGUI event system, which is triggered by you touching the screen.

The code saves when it is pressed down.

It does stuff in Update() which is called every frame if the code is in PressedDown state (mIsPressed == true).

When you lift your finger, a OnPress(false) call is made by the event system, which sets mIsPressed to false, which stops the update loop from doing its thing.

Does that explain it to you?

Daemon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Button (finger on button action) like touch.stationary how ?
« Reply #4 on: July 24, 2014, 05:47:05 PM »
Hi Nicki,

Thank you very much for your explanation. I tested it and it works perfectly :).  I unfortunately didn't  know this important fact about OnPress trigger. Could you send me a link where can I get such similar usefull information ? I thing that I have read documentation quite carefully but I didn't notice any information about this system. Thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile