Hi,
I am trying to do a sort of automatic firing on continuous touch/mouse on a button. I tried to use IPointerDownHandler, but it is only registered on down and not continuously. Am I missing something obvious? coz I can’t for the love of world figure it out. I just need a continuous touch event listener on my button. Can someone help me out, please?
Or something similar to TouchPhase.Stationary works for me as well. I am also trying to make a steering control for vehicle so that when you touch and hold certain part of screen (invisible panel in UI), it will apply the breaks and while holding it down, if you swipe/drag down and then hold again, it will go in reverse.
Register a bool in the IPointerDownHandler, then do your processing in the Update of the MB, in the IPointerUpHandler turn the bool to false.
Check this thread, I had a similar problem and we found a solution.
Thanks for the reply, but it does not solve my problem.
@Tim-C : What I am looking for is while pointer is down, I want to continuously check if the touch is moving or not. if yes, then I want to get the direction and if it’s downwards, then change vehicle state to reverse mode. If it’s not moving, keep holding the brakes. The problem with Drag handler is that I can get isPointerMoving to be true when it’s moving, but I can’t figure out how to get it to false once it stops moving while holding it down. The IPointerUpHandler or IDragEndHandler aren’t useful, because I want to keep the pointer pressed.
In short, I want to get true if the pointer is moving on a panel and false if it stops moving, all the while it is pressed…
I also have a similar question. I have a movement joystick, just a circle. I see in the FAQ there’s a way to find out how far from the center the touch on the button is. However, I can’t figure out how to check that every frame.
I could just use the old method I used before 4.6, but I’d like to do a 4.6 solution
Ideally I’d like to create a button at the location of the player touch, and let the player drag left/right to turn their ship (0% to 100% turn), and move back and forth without removing the finger.
i tried to hack together some old api of touch class to get the touchphase.stationary (stored in global boolean) and the new ui event handlers for the rest of the stuff. It sort of works, but when I checked, the pointerID that I got from onPointerDown was different than the touch.fingerID. So I don’t know how consistent this hack will be if you have more than one touch on screen. Besides, it’s kind of redundant to have to process the touch information with two different systems. I hope there will be a better solution.
Yeah. I guess since the touch part of 4.6 is super buggy, and since this is all new, it’s likely easiest to use the old Input.Touch stuff. I have switched all my current buttons to that and of course it works perfectly. So 4.6 will work for other things at this point, but maybe not for that.
Let’s try this:
When you receive a PointerDown you set a boolean to true, let’s call it “Pressed”. You have a Drag handler that does the movement code you want. You also have a IDragEnd which tests if Pressed is true, and if it is, you brake. Finally you have the PointerUp which sets Pressed to false.