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

相关推荐
weixin_424294671 天前
在Unity中,摄像机移动时出现“残影”或“闪烁”是常见问题,主要原因和处理方法。
unity·游戏引擎
天人合一peng1 天前
unity 3d 通过游戏对象的名子查到其对象
游戏·unity·游戏引擎
UnderTurrets1 天前
A_Survey_on_3D_object_Affordance
pytorch·深度学习·计算机视觉·3d
纯属个人爱好1 天前
Unity2020+PicoNeo3Pro开发
unity·vr
Hao_Harrision1 天前
50天50个小项目 (React19 + Tailwindcss V4) ✨| ThreeDBackgroundBoxes(3D背景盒子组件)
前端·3d·typescript·react·tailwindcss·vite7
__water2 天前
RHK《Unity接入DeepSeek问答》
unity·游戏引擎·智能问答·deepseek接入·deepseekapikey
双翌视觉2 天前
深入解析远心镜头的工作原理与选型
人工智能·数码相机·机器学习
康de哥2 天前
MCP Unity + Claude Code 配置关键步骤
unity·mcp·claude code
美团骑手阿豪2 天前
Unity3D大规模点击检测:GPU Picking vs MeshCollider + Raycast
unity
在路上看风景2 天前
1.4 Unity运行时路径
unity·游戏引擎