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)的位置

相关推荐
多恩Stone6 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
weixin_424294677 天前
Unity 调用Steamworks API 的 SteamUserStats.RequestCurrentStats()报错
unity·游戏引擎·steamwork
HoFunGames7 天前
Unity小地图,Easy Minimap System MT-GPS插件
unity·游戏引擎
多恩Stone7 天前
【3D-AICG 系列-15】Trellis 2 的 O-voxel Shape: Flexible Dual Grid 代码与论文对应
人工智能·python·算法·3d·aigc
在下胡三汉7 天前
为什么“资产土地”标准化主资产的 glTF、glb格式模型,为什么非常流行
3d
2401_863801467 天前
3DTiles(.b3dm,i3dm,cmpt) 数据转换fbx转obj转max转su,cesium格式模型转换
3d
3Dmax效果图渲染研习社7 天前
2026年3ds Max云渲染平台哪个好?
3d
wy3258643647 天前
Unity 新输入系统InputSystem(基本操作)
unity·c#·游戏引擎
WarPigs7 天前
着色器multi_compile笔记
unity·着色器