I am making a Unity3d mobile application. And I have a problem: How to detect touch on UI, or not?
I tried this (but it doesn't work):
UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject();
and this:
private static List<RaycastResult> tempRaycastResults = new List<RaycastResult>();
public bool PointIsOverUI(float x, float y)
{
var eventDataCurrentPosition = new PointerEventData(EventSystem.current);
eventDataCurrentPosition.position = new Vector2(x, y);
tempRaycastResults.Clear();
EventSystem.current.RaycastAll(eventDataCurrentPosition, tempRaycastResults);
return tempRaycastResults.Count > 0;
}