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

相关推荐
留待舞人归2 小时前
【Unity3D优化】优化多语言字体包大小
游戏·unity·游戏引擎·unity3d·优化
SHARE赛尔4 小时前
赛尔发布SHARE 5系列航测相机,外业更高效,建模更优质
数码相机
97650333513 小时前
iOS 审核 cocos 4.3a【苹果机审的“分层阈值”设计】
flutter·游戏·unity·ios
EQ-雪梨蛋花汤1 天前
【Unity笔记】Unity Animation组件使用详解:Play方法重载与动画播放控制
笔记·unity·游戏引擎
AgilityBaby1 天前
Untiy打包安卓踩坑
android·笔记·学习·unity·游戏引擎
元器猫1 天前
工业自动化发展:工业相机在机器视觉领域的应用趋势
运维·数码相机·自动化
菌菌巧乐兹1 天前
Unity | AmplifyShaderEditor插件基础(第九集:旗子进阶版)
unity·游戏引擎
小丑不冷1 天前
50种3D效果演示(OpenGL)
python·3d
广州华锐视点1 天前
3D 展示崛起:科技赋能的新变革
科技·3d·3d展示
lingling0092 天前
智驱未来:迁移科技3D视觉系统重塑复合机器人产业生态
科技·3d·机器人