返回 a
与 b
之间的距离。
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);
}
}
}