Mathf.MoveTowardsAngle 移动角

static function MoveTowardsAngle (current : float, target : float, maxDelta : float) : float

Description描述

Same as MoveTowards but makes sure the values interpolate correctly when they wrap around 360 degrees.

像MoveTowards,但是当它们环绕360度确保插值正确。

Variables current and target are assumed to be in degrees. For optimization reasons, negative values of maxDelta are not supported and may cause oscillation. To push current away from a target angle, add 180 to that angle instead.

变量current和target是作为度数。为优化原因,maxDelta负值的不被支持,可能引起振荡。从target角推开current,添加180度角代替。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public float target = 270.0F;
	public float speed = 45.0F;
	void Update() {
		float angle = Mathf.MoveTowardsAngle(transform.eulerAngles.y, target, speed * Time.deltaTime);
		transform.eulerAngles = new Vector3(0, angle, 0);
	}
}
var target = 270.0;
var speed = 45.0;

function Update () {
	var angle : float = Mathf.MoveTowardsAngle
	(transform.eulerAngles.y, target, speed * Time.deltaTime);
	transform.eulerAngles = Vector3(0, angle, 0);
}
最后修改:2011年2月23日 Wednesday 14:29

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。