3D物体对鼠标左键的响应需要过滤掉UI的情况,具体实现就是通过获取UI检测射线是否检测到UI,只有未检测到UI的时候,才3D物体才可以做出反应
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;
}