- Home /
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 !
Answer by Somshekar · Jul 12, 2019 at 10:56 AM
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;
}
Your answer
Follow this Question
Related Questions
OVRInput keys are not working 0 Answers
Refactor code from getting input from keyboard to get input from UI Buttons 1 Answer
Detect which local player clicked a button 0 Answers
For mobile games, how could you divide the screen into three buttons vertically? 1 Answer
Button.onClick.AddListener 1 Answer