Unity中Mathf.Lerp的⽤法
教程地址:
功能说明:灯光逐渐变亮
private Light myLight;
void Start () {
myLight = GetComponent<Light>();
}
// This would mean the change to intensity would happen per second instead of per frame.
void Update () {
myLight.intensity = Mathf.Lerp(myLight.intensity, 8f, 0.5f * Time.deltaTime);
}
⽤法解释:
例⼦1:
// In this case, result = 4unity 教程
float result = Mathf.Lerp (3f, 5f, 0.5f);
Linearly interpolating is finding a value that is some percentage between two given values.
For example, we could linearly interpolate between the numbers 3 and 5 by 50% to get the number 4. This is because 4 is 50% of the way between 3 and 5.
3和5之间的50%就是4
例⼦2:
Vector3 from = new Vector3 (1f, 2f, 3f);
Vector3 to = new Vector3 (5f, 6f, 7f);
// Here result = (4, 5, 6)
Vector3 result = Vector3.Lerp (from, to, 0.75f);
1和5之间的75%是4