Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: nah0y on June 28, 2012, 05:40:47 PM

Title: Continuous touch detection
Post by: nah0y on June 28, 2012, 05:40:47 PM
Hello !

Let's say I have two buttons on my game, on for going left, the other for going right.
And I want to receive the input everytime one of these buttons is pressed.

At the default configuration of NGUI. I will have to press on the left, release, then press on the right button for example.
But what if I want to stay pressed all the time and just move my mouse/fingers from one button to the other and still receive the pressed event ?

Thanks in advance :)
Title: Re: Continuous touch detection
Post by: JRoch on June 28, 2012, 06:05:03 PM
Try working with OnPress(isDown) since it fires events for both button down and button up.  It'll be up to you to continuously "fire" events while the button state remains down.  This would certainly work with a mouse, as you only ever have one input at a time.  Not sure how it would work with multi-touch.
Title: Re: Continuous touch detection
Post by: nah0y on June 28, 2012, 06:07:07 PM
Thanks for the tip, but not working.

If I'm in a press state, it seems that there is no other event I can receive.
Title: Re: Continuous touch detection
Post by: JRoch on June 28, 2012, 06:19:27 PM
So you're working with a multi-touch device then?  (Scratch that, stupid question.)

How about using lastTouchPosition to then trigger your own raycast and see what colliders it hits?
Title: Re: Continuous touch detection
Post by: nah0y on June 28, 2012, 06:20:12 PM
No no, I'm doing this in the editor for now !
Title: Re: Continuous touch detection
Post by: ArenMook on June 29, 2012, 03:02:03 AM
  1. public class Continuous : MonoBehaviour
  2. {
  3.         bool mIsDown = false;
  4.  
  5.         void OnPress (bool isDown) { mIsDown = isDown; }
  6.  
  7.         void Update ()
  8.         {
  9.                 if (mIsDown)
  10.                 {
  11.                         // Do your stuff
  12.                 }
  13.         }
  14. }
Title: Re: Continuous touch detection
Post by: nah0y on June 29, 2012, 03:06:18 AM
Thanks, but that means I have to send the raycasts myself, right ?
Title: Re: Continuous touch detection
Post by: ArenMook on June 29, 2012, 03:09:13 AM
UICamera.hoveredObject tells you what's under the mouse, whether it's pressed or not.

Edit: See this thread: http://www.tasharen.com/forum/index.php?topic=864.0
Title: Re: Continuous touch detection
Post by: nah0y on June 29, 2012, 03:25:21 AM
Great, thanks !