Vector3.Distance 距离

static function Distance (a : Vector3, b : Vector3) : float

Description描述

Returns the distance between a and b.

返回a和b之间的距离。

Vector3.Distance(a,b) is the same as (a-b).magnitude

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

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Transform other;
	public void Awake() {
		if (typeof(other)) {
			float dist = Vector3.Distance(other.position, transform.position);
			print("Distance to other: " + dist);
		}
	}
}
var other : Transform;
if (other) {
	var dist = Vector3.Distance(other.position, transform.position);
	print ("Distance to other: " + dist);
}
Page last updated: 2010-12-20