//是否点击UI
bool IsRaycastUI_0()
{
//鼠标点击事件
if (EventSystem.current == null || !EventSystem.current.IsPointerOverGameObject())
return false;
else
return true;
}
bool IsRaycastUI_1()
{
if (EventSystem.current == null)
return false;
//鼠标点击事件
PointerEventData pointerEventData = new PointerEventData(EventSystem.current);
//设置鼠标位置
pointerEventData.position = Input.mousePosition;
//射线检测返回结果
List<RaycastResult> results = new List<RaycastResult>();
//检测UI
//graphicRaycaster.Raycast(pointerEventData, results);
EventSystem.current.RaycastAll(pointerEventData, results);
//打印结果
for (int i = 0; i < results.Count; i++)
{
if (results[i].gameObject.CompareTag(""))
{
return true;
}
}
return false;
}