Author Topic: Continuous touch detection  (Read 9841 times)

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Continuous touch detection
« 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 :)

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Continuous touch detection
« Reply #1 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.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Continuous touch detection
« Reply #2 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.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Continuous touch detection
« Reply #3 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?
« Last Edit: June 28, 2012, 06:21:34 PM by JRoch »

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Continuous touch detection
« Reply #4 on: June 28, 2012, 06:20:12 PM »
No no, I'm doing this in the editor for now !

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Continuous touch detection
« Reply #5 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. }

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Continuous touch detection
« Reply #6 on: June 29, 2012, 03:06:18 AM »
Thanks, but that means I have to send the raycasts myself, right ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Continuous touch detection
« Reply #7 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
« Last Edit: June 29, 2012, 03:18:27 AM by ArenMook »

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Continuous touch detection
« Reply #8 on: June 29, 2012, 03:25:21 AM »
Great, thanks !