纳金网
标题:
检测是否点击到UI的代码
[打印本页]
作者:
may
时间:
2019-12-15 10:23
标题:
检测是否点击到UI的代码
来自:F1085645195
private GraphicRaycaster _raycaster;//图形射线(只检测继承Graphic的组件,一般是UI)
private void Start()
{
_raycaster = FindObjectOfType<GraphicRaycaster>();
}
/// <summary>
/// 检测是否点击UI
/// </summary>
/// <returns></returns>
private bool IsUI()
{
PointerEventData data = new PointerEventData(EventSystem.current);
data.pressPosition = Input.mousePosition;
data.position = Input.mousePosition;
List<RaycastResult> results = new List<RaycastResult>();
_raycaster.Raycast(data, results);
return results.Count > 0;
}
复制代码
作者:
745951224
时间:
2019-12-17 09:11
这是个不错的方法,相比于直接调用UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()让人更能明确其原理
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5