Unity 判断是否点击在UI上面
public bool IsPointerOverGameObject(Vector2 screenPosition)
{
if (Input.GetMouseButtonDown(0))
{
//实例化点击事件
PointerEventData eventDataCurrentPosition = new PointerEventData(UnityEngine.EventSystems.EventSystem.current);
//将点击位置的屏幕坐标赋值给点击事件
eventDataCurrentPosition.position = new Vector2(screenPosition.x, screenPosition.y);
List<RaycastResult> results = new List<RaycastResult>();
//向点击处发射射线
EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
return results.Count > 0;
}
return false;
}
private bool IsTouchedUI()//是否点击在UI上
{
bool touchedUI = true;
#if UNITY_ANDROID
// Debug.Log("安卓设备");
touchedUI = IsPointerOverGameObject(Input.mousePosition);
#endif
#if UNITY_STANDALONE_WIN
// Debug.Log("从