Mathf.Lerp 插值

static function Lerp (from : float, to : float, t : float) : float

Description描述

Interpolates a towards b by t. t is clamped between 0 and 1.

基于浮点数t返回a到b之间的插值,t限制在0~1之间。

When t = 0 returns from. When t = 1 return to. When t = 0.5 returns the average of a and b.

当t = 0返回from,当t = 1 返回to。当t = 0.5 返回from和to的平均值。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public float minimum = 10.0F;
	public float maximum = 20.0F;
	void Update() {
		transform.position = new Vector3(Mathf.Lerp(minimum, maximum, Time.time), 0, 0);
	}
}
// Fades from minimum to maximum in one second
// 在一秒内从minimum渐变到maximum

var minimum = 10.0;
var maximum = 20.0;

function Update () {
	transform.position = Vector3(Mathf.Lerp(minimum, maximum, Time.time), 0, 0);
}
最后修改:2011年2月23日 Wednesday 14:09

本脚本参考基于Unity 3.4.1f5

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