Mathf
- Abs
- Acos
- Approximately
- Asin
- Atan2
- Atan
- CeilToInt
- Ceil
- Clamp01
- Clamp
- ClosestPowerOfTwo
- Cos
- Deg2Rad
- DeltaAngle
- Epsilon
- Exp
- FloorToInt
- Floor
- Infinity
- InverseLerp
- IsPowerOfTwo
- LerpAngle
- Lerp
- Log10
- Log
- Max
- Min
- MoveTowardsAngle
- MoveTowards
- NegativeInfinity
- NextPowerOfTwo
- PingPong
- PI
- Pow
- Rad2Deg
- Repeat
- RoundToInt
- Round
- Sign
- Sin
- SmoothDampAngle
- SmoothDamp
- SmoothStep
- Sqrt
- Tan
Mathf.MoveTowards 移向
static function MoveTowards (current : float, target : float, maxDelta : float) : float
Description描述
Moves a value current towards target.
改变一个当前值向目标值靠近。
This is essentially the same as Mathf.Lerp but instead the function will ensure that the speed never exceeds maxDelta. Negative values of maxDelta pushes the value away from target.
这实际上和 Mathf.Lerp相同,而是该函数将确保我们的速度不会超过maxDelta。maxDelta为负值将目标从推离。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public float target = 20.0F;
public float speed = 5.0F;
void Update() {
transform.position = new Vector3(Mathf.MoveTowards(transform.position.x, target, speed * Time.deltaTime), 0, 0);
}
}
var target = 20.0;
var speed = 5.0;
function Update() {
transform.position = Vector3(Mathf.MoveTowards
(transform.position.x, target, speed * Time.deltaTime), 0, 0);
}
最后修改:2011年2月23日 Wednesday 14:20