Skip to main content
Describe the problem in title, code formatting
Source Link
DMGregory
  • 141k
  • 23
  • 258
  • 401

In Unity Problem With How to distinguish pointer up inside button Inputvs drag-out

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 pointerUpOnPointerUp method 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?

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?

How to distinguish pointer up inside button vs drag-out

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 OnPointerUp method 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?

Source Link
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?