unity检测鼠标是点击在UI上还是物体上

void Update()
	{
		if (Input.GetMouseButtonDown(0)||(Input.touchCount >0 && Input.GetTouch(0).phase == TouchPhase.Began))
		{
#if IPHONE || ANDROID
			if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
#else
			if (EventSystem.current.IsPointerOverGameObject())
#endif
				Debug.Log("当前触摸在UI上");
			
			else 
				Debug.Log("当前没有触摸在UI上");
		}
	}

  

原文地址:https://www.cnblogs.com/943711466qq/p/6476549.html