|
- public Color startColor;
- public Color endColor;
- public float duration = 1.0f;
- private float startTime;
- void Start()
- {
- startTime = Time.time;
- }
- void Update()
- {
- float t = (Time.time - startTime) / duration;
- GetComponent<Renderer>().material.color = Color.Lerp(startColor, endColor, t);
- }
复制代码- public Transform startMarker;
- public Transform endMarker;
- public float speed = 1.0f;
- private float startTime;
- private float journeyLength;
- void Start()
- {
- startTime = Time.time;
- journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
- }
- void Update()
- {
- float distCovered = (Time.time - startTime) * speed;
- float fractionOfJourney = distCovered / journeyLength;
- transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fractionOfJourney);
- }
复制代码 例子一:渐变
例子二:平滑移动物体的位置
|
|