下面例子实现点光源的移动在场景中创建好一个平面,一个点光源,我在这里随便放了一个模型。然后新建c#脚本,代码如下:using UnityEngine;using System.Collections;public class Lerp : MonoBehaviour { public Vector3 newPos; // Use this for initialization void Start () { newPos = transform.position; } // Update is called
once per frame void Update () { if(Input.GetKeyDown(KeyCode.Q)) newPos = new Vector3(-3,8,22); if(Input.GetKeyDown(KeyCode.E)) newPos = new Vector3(3,8,22); transform.position = Vector3.Lerp(transform.position,newPos,Time.deltaTime); }} 然后将脚本拖动到点光上面,按下键盘Q和E键就可以看到效果了。上面是用Vector3的Lerp函数进行缓动的。里面的参数是(Vector3
from,Vector3 to,float time);比如我们想改变light的颜色或者强度intensity,那么参数是2个浮点数,我们就可以用Mathf.Lerp(float from,float to,float time)进行缓动了。
Unity的Lerp函数实现缓动
最新推荐文章于 2026-05-15 05:25:53 发布
本文介绍如何在Unity中使用C#脚本实现点光源的平滑移动。通过键盘按键控制点光源的位置变化,并利用Vector3.Lerp函数完成缓动效果。

3672

被折叠的 条评论
为什么被折叠?



