[Solved] Tapping a UI button

I noticed that when you press a UI button, it doesn’t matter how long you press it, it will always register and activate.
What if you want to make it only activate on “Tap”? And a tap would be up to 1 second. Is this possible to do with the new UI system?

Yes it’s possible. You would just need to create a script with the IPointerDownhandler and IPointerUpHandler interfaces.

Then keep a timer between the events occurring and only action when it is within a certain time limit.

What would I do once I have created the script? How would I use it with the Button component?

Just attach it to a Button GO, it will work side by side with the existing button behaviour. Or alternatively, inherit from the Button script and override the default behaviour if you wish.
You can check the Button’s source here:
https://bitbucket.org/Unity-Technologies/ui/src/5fc21bb4ecf4b40ff6630057edaa070252909b2e/UnityEngine.UI/UI/Core/Button.cs?at=4.6

1 Like

Thanks that’s really useful. I already made it inherit from Button but public variables don’t show in the Inspector. I’ll try to just copy & paste the code you posted and see how it works with that.
Thanks.