Skip to main content
1 of 2
zmac
  • 11
  • 1

In Unity Problem With button Input

I am making a unity mobile game, I have a simple scene and a canvas with a few buttons and these buttons have scripts that detect if the button was pressed and released. Here is the code for doing this:

public class InteractiveButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{ 
  
public void OnPointerDown(PointerEventData eventData)
{
    //do something
}

public void OnPointerUp(PointerEventData eventData)
{
    //do something
}

}

This works perfectly fine as when i press the button the down event gets triggered as expected, but if i keep my finger pressed and drag my fingers off the bounds of the button and let go the pointerUp still gets called as if I let my finger go on the button.

So how can I detect if the player lets go out of the buttons bounds?

zmac
  • 11
  • 1