From 1afc770eef390503444b910a1ac9b26044b83f6d Mon Sep 17 00:00:00 2001 From: yangbear Date: Sun, 12 Jul 2026 04:05:19 +0800 Subject: [PATCH] Fix NullReferenceException in ChanraoTuibuHandler by disabling instead of destroying BoxCollider --- Assets/Scripts/Interaction/ChanraoTuibuHandler.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/Interaction/ChanraoTuibuHandler.cs b/Assets/Scripts/Interaction/ChanraoTuibuHandler.cs index 7f18323..8f91d82 100644 --- a/Assets/Scripts/Interaction/ChanraoTuibuHandler.cs +++ b/Assets/Scripts/Interaction/ChanraoTuibuHandler.cs @@ -2,7 +2,6 @@ using UnityEngine; public class ChanraoTuibuHandler : MonoBehaviour { - private MeshRenderer _outlineMesh; private float _lastClickTime; private bool _isFinished; @@ -28,9 +27,8 @@ public class ChanraoTuibuHandler : MonoBehaviour if (ping004 != null) { - // 将 ping.004 的世界坐标转换到当前物体的局部坐标系 col.center = transform.InverseTransformPoint(ping004.transform.position); - col.radius = 0.8f; // 弄大一点确保能点到 + col.radius = 0.8f; col.enabled = true; Debug.Log($"[ChanraoTuibu] 碰撞体已定位到 ping.004 的位置: {col.center}"); } @@ -40,9 +38,9 @@ public class ChanraoTuibuHandler : MonoBehaviour col.radius = 0.8f; } - // 删除可能遗留的错误 BoxCollider + // 不要在代码中直接 Destroy BoxCollider,避免 Unity Editor 抛出异常 var box = GetComponent(); - if (box != null) Destroy(box); + if (box != null) box.enabled = false; foreach (var r in GetComponentsInChildren(true)) r.enabled = false; CreateOutlineMesh(); @@ -113,7 +111,7 @@ public class ChanraoTuibuHandler : MonoBehaviour var allPings = Object.FindObjectsOfType(); foreach (var p in allPings) { - if (p.gameObject.activeInHierarchy) // Wait, pings are still active, they just have _modelShown = true + if (p.gameObject.activeInHierarchy) { p.ReEnableBorder(); }