Fix NullReferenceException in ChanraoTuibuHandler by disabling instead of destroying BoxCollider
This commit is contained in:
@@ -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<BoxCollider>();
|
||||
if (box != null) Destroy(box);
|
||||
if (box != null) box.enabled = false;
|
||||
|
||||
foreach (var r in GetComponentsInChildren<Renderer>(true)) r.enabled = false;
|
||||
CreateOutlineMesh();
|
||||
@@ -113,7 +111,7 @@ public class ChanraoTuibuHandler : MonoBehaviour
|
||||
var allPings = Object.FindObjectsOfType<PingClickHandler>();
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user