Unity 检测点击UI
EventSystem eventSystem = EventSystem.current;
PointerEventData pointerEventData = new PointerEventData(eventSystem);
pointerEventData.position = Input.mousePosition;
//射线检测ui
List uiRaycastResultCache = new List();
eventSystem.RaycastAll(pointerEventData, uiRaycastResultCache);
if (uiRaycastResultCache.Count > 0)
{
//根据需求还可以附加判断条件
//foreach(RaycastResult result in uiRaycastResultCache)
//{
// if (result.gameObject == this || result.gameObject == popMenu || result.gameObject ==selfButton.gameObject)
// return true;
//}
//return false;
return true;
}
return false;



