Version: 2021.3
public static float Distance (Vector3 a, Vector3 b);

描述

返回 ab 之间的距离。

Vector3.Distance(a,b)(a-b).magnitude 相同。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Transform other;

void Example() { if (other) { float dist = Vector3.Distance(other.position, transform.position); print("Distance to other: " + dist); } } }