uGUI没有一个标志或接口检测是否点击在了UI上,这点不太友好,不过也有解。
E.g.
Using System.EventSystem;
...
if (Input.touchCount > 0 || Input.GetMouseButton (0))
{
Vector2 point = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
PointerEventData eventData = new PointerEventData (EventSystem.Current);
eventData.position = point;
tempRaycastResultList.Clear();
EventSystem.current.RaycastAll (eventData, tempRaycastResultList);
return tempRaycastResultList.Count > 0;
}
不像网上有些人说的,EventSystem.Current.IsPointerOverGameObject (Input.GetTouch(0).fingerId)中iOS上始终返回false,而在PC和Mac上功能都正常,能够识别是否点击在了UI上,姑且认为这是Unity的bug吧(至少Unity5.1.1f上存在)。