How to Implement Swipe Up/Down Detection on Fullscreen Canvas UI Button

Hi there,

I currently have a fullscreen canvas UI button that works perfectly with click/tap interactions. However, I would like to extend its functionality to also detect swipe gestures, specifically swipe up and swipe down, while keeping the original click/tap behavior intact.

Could you please advise on the best way to implement swipe detection on this button, and if there are any potential issues I should be aware of when combining both types of interactions?

Thank you for your help!

well, there are several aspects to consider, you’d basically gate your swipe detector using a dragThreshold (your InputSystem’s default one would do – EventSystem.current.pixelDragThreshold).

you might get away with just overlaying an image on top of your button and add a script which only ‘captures’ the pointer event once it moves beyond that pixelDragThreshold.

start here: Unity - Scripting API: IInitializePotentialDragHandler
then IBeginDragHandler, IEndDragHandler

the eventData you receive in those calls will contain everything you need to calculate distance etc.

1 Like