Mathf.Lerp
public static float Lerp(float a, float b, float t);
Description
Linearly interpolates between a and b by t.
The parameter t is clamped to the range [0, 1].
When t = 0 returns a.
When t = 1 return b.
When t = 0.5 returns the midpoint of a and b.
using UnityEngine; using System.Collections; /* *Lerp插值运算 *速度会慢慢的减少 */ public class DemoController : MonoBehaviour { //public Transform cube; public GameObject cube; private void Update() { //float x = cube.position.x; float x = cube.transform.position.x; float newX = Mathf.Lerp(x, 10, Time.deltaTime); //float newX = Mathf.Lerp(x, 10, 0.1f); //cube.position = new Vector3(newX, 0, 0); cube.transform.position = new Vector3(newX, 0, 0); } }