UI button and Touch Input conflict

Hello everyone,

I have a conflit.

In my Update loop I have
if(Input.touches.Any(touch => touch.phase == TouchPhase.Began)) // Do stuff

However, I also put a button with a click event on the script.

And when I click on the button, it’s the Update loop which handle the event and not the Click Event.

Do you know how is it possible to handle the button with the click button with the Update loop active ?

Thank you and have a nice day !

Try this:

void Update
{
        if (IsPointerOverUIObject())
                return;
       //Your code here
 }
 private bool IsPointerOverUIObject()
 {
        PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
        eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
        List<RaycastResult> results = new List<RaycastResult>();
        EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
        return results.Count > 0;
  }