2D
private void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.GetComponent<AttackBox>()) { hitPos = other.bounds.ClosestPoint(transform.position); print("碰撞點" + hisPos); } }
3D
other.gameObject.GetComponent<Collider>().ClosestPointOnBounds(transform.position);
注意這種方法不推薦單場景里過多使用,會產生大量的GC 影響幀率