| from | 范围的开始。 |
| to | 范围的结束。 |
| t | 在from和to范围限制之间的插值值。 |
float 在from和to之间插值的浮点数结果。
在from和to之间插值,并在限制处进行平滑处理。
此函数以类似于Lerp的方式在from和to之间插值。但是,插值将从开始逐渐加速,并在结束时逐渐减速。这对于创建自然逼真的动画、淡入淡出和其他过渡很有用。
参数t被限制在 [0, 1] 范围内。
using UnityEngine;
public class Example : MonoBehaviour { // Minimum and maximum values for the transition. float minimum = 10.0f; float maximum = 20.0f;
// Time taken for the transition. float duration = 5.0f;
float startTime;
void Start() { // Make a note of the time the script started. startTime = Time.time; }
void Update() { // Calculate the fraction of the total duration that has passed. float t = (Time.time - startTime) / duration; transform.position = new Vector3(Mathf.SmoothStep(minimum, maximum, t), 0, 0); } }