diff --git a/Assets/Scripts/Interaction/ChanraoTuibuHandler.cs b/Assets/Scripts/Interaction/ChanraoTuibuHandler.cs index be9d9ae..7f18323 100644 --- a/Assets/Scripts/Interaction/ChanraoTuibuHandler.cs +++ b/Assets/Scripts/Interaction/ChanraoTuibuHandler.cs @@ -11,25 +11,39 @@ public class ChanraoTuibuHandler : MonoBehaviour void OnEnable() { - // 自动添加并适配包裹该物体网格的 BoxCollider,保证鼠标可以点到 - var mesh = GetMesh(); - if (mesh != null) + // 尝试以 ping.004 为中心生成碰撞体,因为如果它是 SkinnedMeshRenderer,其自身原点可能在脚底 + var col = GetComponent(); + if (col == null) col = gameObject.AddComponent(); + + var ping004 = GameObject.Find("ping.004"); + if (ping004 == null) { - var oldSph = GetComponent(); - if (oldSph != null) Destroy(oldSph); - - var col = GetComponent(); - if (col == null) col = gameObject.AddComponent(); - - col.center = mesh.bounds.center; - col.size = mesh.bounds.size * 1.2f; + var mi = GameObject.Find("manInjury"); + if (mi != null) + { + var t = mi.transform.Find("ping.004"); + if (t != null) ping004 = t.gameObject; + } + } + + if (ping004 != null) + { + // 将 ping.004 的世界坐标转换到当前物体的局部坐标系 + col.center = transform.InverseTransformPoint(ping004.transform.position); + col.radius = 0.8f; // 弄大一点确保能点到 col.enabled = true; + Debug.Log($"[ChanraoTuibu] 碰撞体已定位到 ping.004 的位置: {col.center}"); } else { - if (GetComponent() == null) gameObject.AddComponent().radius = 0.5f; + col.center = Vector3.zero; + col.radius = 0.8f; } - + + // 删除可能遗留的错误 BoxCollider + var box = GetComponent(); + if (box != null) Destroy(box); + foreach (var r in GetComponentsInChildren(true)) r.enabled = false; CreateOutlineMesh(); _isFinished = false;