【发布时间】:2022-05-03 14:39:42
【问题描述】:
在制作 Unity3d 移动应用程序时。我有一个问题:如何检测 UI 上的触摸?
我试试这个(但现在可以了)
UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()
还有这个
private static List<RaycastResult> tempRaycastResults = new List<RaycastResult>();
public bool PointIsOverUI(float x, float y)
{
var eventDataCurrentPosition = new PointerEventData(EventSystem.current);
eventDataCurrentPosition.position = new Vector2(x, y);
tempRaycastResults.Clear();
EventSystem.current.RaycastAll(eventDataCurrentPosition, tempRaycastResults);
return tempRaycastResults.Count > 0;
}
【问题讨论】: