Update RayTool.cs

This commit is contained in:
MuHua-123
2025-12-24 16:06:51 +08:00
parent 4bd3077e50
commit ea665c58cd
@@ -39,7 +39,7 @@ namespace MuHua {
/// <summary> 屏幕坐标转世界坐标 </summary> /// <summary> 屏幕坐标转世界坐标 </summary>
public static bool GetScreenToWorldPosition(Camera camera, Vector3 screen, out Vector3 position, LayerMask planeLayerMask) { public static bool GetScreenToWorldPosition(Camera camera, Vector3 screen, out Vector3 position, LayerMask planeLayerMask) {
Ray ray = camera.ScreenPointToRay(screen); Ray ray = camera.ScreenPointToRay(screen);
Physics.Raycast(ray, out hitInfo, 200, planeLayerMask); Physics.Raycast(ray, out hitInfo, 500, planeLayerMask);
position = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue); position = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
if (hitInfo.transform != null) { position = hitInfo.point; } if (hitInfo.transform != null) { position = hitInfo.point; }
return hitInfo.transform != null; return hitInfo.transform != null;
@@ -77,7 +77,7 @@ namespace MuHua {
/// <summary> 从屏幕坐标获取对象 </summary> /// <summary> 从屏幕坐标获取对象 </summary>
public static bool GetScreenToWorldObject<T>(Camera camera, Vector3 screen, out T value, LayerMask planeLayerMask) where T : Object { public static bool GetScreenToWorldObject<T>(Camera camera, Vector3 screen, out T value, LayerMask planeLayerMask) where T : Object {
Ray ray = camera.ScreenPointToRay(screen); Ray ray = camera.ScreenPointToRay(screen);
Physics.Raycast(ray, out hitInfo, 200, planeLayerMask); Physics.Raycast(ray, out hitInfo, 500, planeLayerMask);
value = hitInfo.transform?.GetComponent<T>(); value = hitInfo.transform?.GetComponent<T>();
return value != null; return value != null;
} }
@@ -114,7 +114,7 @@ namespace MuHua {
/// <summary> 从屏幕坐标获取碰撞信息 </summary> /// <summary> 从屏幕坐标获取碰撞信息 </summary>
public static bool GetScreenToWorldHitInfo(Camera camera, Vector3 screen, out RaycastHit hitInfo, LayerMask planeLayerMask) { public static bool GetScreenToWorldHitInfo(Camera camera, Vector3 screen, out RaycastHit hitInfo, LayerMask planeLayerMask) {
Ray ray = camera.ScreenPointToRay(screen); Ray ray = camera.ScreenPointToRay(screen);
return Physics.Raycast(ray, out hitInfo, 200, planeLayerMask); return Physics.Raycast(ray, out hitInfo, 500, planeLayerMask);
} }
} }
} }