Vector3.Angle 角度
static function Angle (from : Vector3, to : Vector3) : float
Description描述
Returns the angle in degrees between from and to.
由from和to两者返回一个角度。形象的说,from和to的连线和它们一个指定轴向的夹角。
C#
JavaScript
using UnityEngine;using System.Collections;public class example : MonoBehaviour {public Transform target;void Update() {Vector3 targetDir = target.position - transform.position;Vector3 forward = transform.forward;float angle = Vector3.Angle(targetDir, forward);if (angle < 5.0F)print("close");}}
// prints "close" if the z-axis of this transform looks// almost towards the target//如果当前变换z轴接近目标小于5度的时候,打印"close"var target : Transform;function Update () {var targetDir = target.position - transform.position;var forward = transform.forward;var angle = Vector3.Angle(targetDir, forward);if (angle < 5.0)print("close");}