Version: 2021.1
public static ColliderDistance2D Distance (Collider2D colliderA, Collider2D colliderB);

参数

colliderA A Collider used to calculate the minimum distance against colliderB.
colliderB A Collider used to calculate the minimum distance against colliderA.

返回

ColliderDistance2D colliderAcolliderB 之间的最小距离。

描述

Calculates the minimum distance between two Colliders.

要使返回的 ColliderDistance2D 有效,必须提供有效的 colliderAcolliderA,也就是说,colliderAcolliderB 不应为 NULL、不应禁用并且必须包含碰撞形状。可以通过检查 ColliderDistance2D.isValid 来检查返回的值是否有效。

另请参阅:Collider2D.DistanceRigidbody2D.Distance