- Home /
Unity 4.6 New UI Touch Detection
I have some Image UI Elements which represent buttons and I need to detect whether player touched them and if he's still holding the button or not, any ideas?
Answer by PedroGV · Oct 09, 2014 at 05:18 AM
The way I achieve that is by adding an EventTrigger component to the UI Element (say, an image) and then add a new event to it, like Pointer Down. Then, I assign the game object that will handle the event and select the proper function/operation from it.
Sure I tried this too but I need to call that method each frame while user's holding that BTN, or is there any documentation on these Trigger's becouse I didnt got difference between PointerClick and Pointer Down and events like this...?
Unfortunately, you will have to handle that with two events, PointerDown and PointerUp, both say, calling the same operations with a boolean parameter (and store the value of the parameter in a field). And then, on the update operation of your script you will have to check the value of that field in order to do actions while the button is still held by the user.
I agree it may be a bit counter-intuitive, since one may think thet PointerDown is an event that happens while the pointer is down and not just the first time is down.
Click = Down then Up in relatively small timeframe.