From 406714df7d860b680edabf7cb966fb972fe520c3 Mon Sep 17 00:00:00 2001 From: yangbear Date: Sun, 5 Jul 2026 21:33:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Physics.RaycastAll=E6=89=AB=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E5=91=BD=E4=B8=AD=E2=80=94Ground=E9=98=BB=E6=8C=A1?= =?UTF-8?q?=E4=B9=9F=E4=B8=8D=E5=BD=B1=E5=93=8D=E9=9E=8B=E5=AD=90=E7=82=B9?= =?UTF-8?q?=E5=87=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/Interaction/ShoseClickHandler.cs | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Assets/Scripts/Interaction/ShoseClickHandler.cs b/Assets/Scripts/Interaction/ShoseClickHandler.cs index e6d73f3..0509dff 100644 --- a/Assets/Scripts/Interaction/ShoseClickHandler.cs +++ b/Assets/Scripts/Interaction/ShoseClickHandler.cs @@ -18,7 +18,7 @@ public class ShoseClickHandler : MonoBehaviour StopAllCoroutines(); StartCoroutine(BlinkOutline()); _clicked = false; - Debug.Log($"[ShoseClick] OnEnable outline={_outlineMesh!=null} col={(col is SphereCollider sc2?sc2.radius:-1)}"); + Debug.Log($"[ShoseClick] OnEnable outline={_outlineMesh!=null} col={((SphereCollider)col).radius}"); } void CreateOutlineMesh() @@ -44,11 +44,7 @@ public class ShoseClickHandler : MonoBehaviour { if (_outlineMesh != null) _outlineMesh.enabled = true; yield return new WaitForSeconds(0.4f); - while (true) - { - if (_outlineMesh != null) _outlineMesh.enabled = !_outlineMesh.enabled; - yield return new WaitForSeconds(0.4f); - } + while (true) { if (_outlineMesh != null) _outlineMesh.enabled = !_outlineMesh.enabled; yield return new WaitForSeconds(0.4f); } } void Update() @@ -57,11 +53,13 @@ public class ShoseClickHandler : MonoBehaviour foreach (var cam in Camera.allCameras) { if (!cam.enabled) continue; - Ray ray = cam.ScreenPointToRay(Input.mousePosition); - if (Physics.Raycast(ray, out RaycastHit hit, 100f) && hit.collider != null && hit.collider.gameObject == gameObject) + var hits = Physics.RaycastAll(cam.ScreenPointToRay(Input.mousePosition), 100f); + foreach (var h in hits) { - OnClicked(); - return; + if (h.collider != null && h.collider.gameObject == gameObject) + { + OnClicked(); return; + } } } } @@ -72,8 +70,7 @@ public class ShoseClickHandler : MonoBehaviour Debug.Log("[ShoseClick] ★ 被点击了 ★"); StopAllCoroutines(); if (_outlineMesh != null) _outlineMesh.enabled = false; - if (targetPoint != null) { transform.position = targetPoint.position; transform.rotation = targetPoint.rotation; Debug.Log($"[ShoseClick] 移动到 {targetPoint.name}"); } - else Debug.LogWarning("[ShoseClick] targetPoint 为空"); + if (targetPoint != null) { transform.position = targetPoint.position; transform.rotation = targetPoint.rotation; } if (nextObject != null) nextObject.SetActive(true); } }