我正在开发一款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;
}