您的位置:首页 > 移动开发 > Unity3D

Unity uGUI鼠标击穿检测

2015-11-02 21:49 489 查看
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上存在)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: