Unity中Mathf.Lerp的用法

教程地址:

https://learn.unity.com/tutorial/linear-interpolation?language=en&projectId=5c8920b4edbc2a113b6bc26a#5c8a48bdedbc2a001f47cef6

功能说明:灯光逐渐变亮

   private Light myLight;
    void Start () {
        myLight = GetComponent();
    }
    
    // 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 = 4

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

 

你可能感兴趣的:(Unity中Mathf.Lerp的用法)