Vector3.Distance

计算两点间距离。

定义

public static float Distance(Vector3 a, Vector3 b);
参数名类型必要说明
aVector3a 点
bVector3b 点

示例

using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    public Transform target;

    private bool IsClose()
    {
        if (!target) return false;
        var distance = Vector3.Distance(transform.position, target.position);
        return distance < 10.0f;
    }
}