unity ui raycast blocker code example
Example: unity ui doesn't block raycast
private bool IsOverUI(TouchState touch)
{
PointerEventData pointerData = new PointerEventData(EventSystem.current);
pointerData.position = touch.position;
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointerData, results);
if (results.Count > 0)
{
for (int i = 0; i < results.Count; i++)
{
if (results[i].gameObject.GetComponent<CanvasRenderer>())
{
return true;
}
}
}
return false;
}