Unityは2衝突体との間の距離を計算します

//    _____        _____
//   |     |      |     |
//   |  x==|======|==x  |   是错误的
//   |_____|      |_____|
//
//    _____        _____
//   |     |      |     |
//   |     |x====x|     |   正确的
//   |_____|      |_____|
//
//计算两物体间的距离
public float Distance(Collider a, Collider b)
{
    return Vector3.Distance(a.ClosestPointOnBounds(b.transform.position),
                            b.ClosestPointOnBounds(a.transform.position));
}
公開された14元の記事 ウォンの賞賛0 ビュー422

おすすめ

転載: blog.csdn.net/a0_67/article/details/104407803