Unity 3D基础——缓动效果

1.在场景中新建两个 Cube 立方体,在 Scene 视图中将两个 Cude的位置错开。

2.新建 C# 脚本 MoveToTarget.cs(写完记得保存)

cs 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveToTarget : MonoBehaviour
{
    public Transform endTrans;  //定义结束位置的 Transform 对象

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        //脚本所在位置缓动到 endTrans 的位置
        transform.position = Vector3.Lerp(transform.position, endTrans.position, Time.deltaTime);
    }
}

3.将脚本绑定到 Cude 上,然后将其 Inpector 视图中将 endTrans 指定为 Cube(1) (我命名的是Arm)。(让A缓动到B,就把脚本绑定在A上,endTrans 设置为 B)

4.点击播放按钮,可以看到 Cube 缓动到 Cube(1) (我的Arm)的位置

相关推荐
高升说3 小时前
光与影的邂逅-09-太亮的地方
数码相机·深度相机
雾沉川4 小时前
d3dx9_43.dll 丢失报错原因分析及三种标准修复方法
microsoft·3d
zhchyun20087 小时前
【Unity UI 进阶】仿 Element UI 打造企业级 Unity UI 组件库(05)
ui·unity·游戏引擎
蓝速科技9 小时前
蓝速科技圆柱形 3D 全息舱全天候值守实战指南
科技·3d
2601_966871409 小时前
AE影视后期特效-遮罩/调色/抠像/MG动画/3D/Vlog制作
3d
狂云歌10 小时前
AI写UE的3Dgame
人工智能·3d·ue5·游戏程序
_ZHOURUI_H_10 小时前
不做完整 ECS,只优化数据布局:Unity EasyECS 到底是什么
unity·性能优化·游戏引擎
高升说11 小时前
光与影的邂逅-08-丢失的光
数码相机·深度相机
jeffsonfu1 天前
卷积不止于2D:掌握1D、2D、3D卷积的适用场景
3d
CVer儿1 天前
ras转为lps坐标系
数码相机