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 影响帧率