Fix syntax error and finalize absolute collider sizing for pings

This commit is contained in:
yangbear
2026-07-12 05:10:07 +08:00
parent 3ca4dcca6f
commit efce075c1f
+18 -25
View File
@@ -16,34 +16,27 @@ public class PingClickHandler : MonoBehaviour
if (_modelRenderer == null) _modelRenderer = GetComponentInChildren<MeshRenderer>();
foreach (var r in GetComponentsInChildren<Renderer>(true)) r.enabled = false;
var col = GetComponent<Collider>();
if (col == null)
var colliders = GetComponents<Collider>();
foreach (var c in colliders)
{
var box = gameObject.AddComponent<BoxCollider>();
box.size = new Vector3(2f, 2f, 2f);
col = box;
if (c is SphereCollider || c is CapsuleCollider)
{
Destroy(c);
}
}
// 终极修复:直接无视它原来的任何比例,强制改成非常庞大的数值!
// 因为你的模型在世界坐标里 lossyScale 达到了 100x73x100,所以局部半径会被算得很小(0.006)。
// 现在我直接给它一个固定的局部半径 = 1.0f。在放大 100 倍后,这个球的大小就是 100 米长!
// 这绝对绝对不可能点不到了。
if (col is SphereCollider sphere)
{
sphere.radius = 2.0f;
}
else if (col is BoxCollider box)
{
box.size = new Vector3(4.0f, 4.0f, 4.0f);
}
else if (col is CapsuleCollider cap)
{
cap.radius = 2.0f;
cap.height = 4.0f;
}
col.isTrigger = false;
col.enabled = true;
var box = GetComponent<BoxCollider>();
if (box == null) box = gameObject.AddComponent<BoxCollider>();
Vector3 lossy = transform.lossyScale;
float sx = Mathf.Clamp(0.5f / Mathf.Max(Mathf.Abs(lossy.x), 0.001f), 0.001f, 100f);
float sy = Mathf.Clamp(0.5f / Mathf.Max(Mathf.Abs(lossy.y), 0.001f), 0.001f, 100f);
float sz = Mathf.Clamp(0.5f / Mathf.Max(Mathf.Abs(lossy.z), 0.001f), 0.001f, 100f);
box.size = new Vector3(sx, sy, sz);
box.center = Vector3.zero;
box.isTrigger = false;
box.enabled = true;
CreateOutlineMesh();
_modelShown = false;