public bool IsOnUI(Vector3 pos)
{
GraphicRaycaster caster = gameObject.GetComponent<GraphicRaycaster>();
PointerEventData pData = new PointerEventData(EventSystem.current);
pData.position = pos;
pData.delta = Vector2.zero;
pData.scrollDelta = Vector2.zero;
List<UnityEngine.EventSystems.RaycastResult> canvasHits = new List<UnityEngine.EventSystems.RaycastResult>();
caster.Raycast(pData, canvasHits);
return canvasHits.Count > 0;
}
原理也是UI的射线检测。