Unity 动画(旧版-新版)

旧版

旧版-动画组件:Animation

窗口-动画

动画文件后缀: .anim

将制作后的动画拖动到Animation组件上

旧版的操作

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

public class c1 : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            GetComponent<Animation>().Play("r1");
        }
    }
}

新版

新版动画组件:Animator

控制器需要在项目中创建:动画控制器

双击新建动画控制器

点击场景中的物体,点击窗口-动画,使用"动画"开始制作2个动画

运行时

鼠标左键点击播放动画1,右键点击播放动画2.

代码实现

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

public class c2 : MonoBehaviour
{
    private Animator animator;

    void Start()
    {
        // 获取动画器组件
        animator = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            animator.Play("r2");
        }

        if (Input.GetMouseButtonDown(1))
        {
            animator.Play("r1");
        }
    }
}
相关推荐
weixin_4242946712 天前
Unity 调用Steamworks API 的 SteamUserStats.RequestCurrentStats()报错
unity·游戏引擎·steamwork
HoFunGames12 天前
Unity小地图,Easy Minimap System MT-GPS插件
unity·游戏引擎
wy32586436412 天前
Unity 新输入系统InputSystem(基本操作)
unity·c#·游戏引擎
WarPigs12 天前
着色器multi_compile笔记
unity·着色器
ECHO飞跃 01212 天前
Unity2019 本地推理 通义千问0.5-1.5B微调导入
人工智能·深度学习·unity·llama
Unity游戏资源学习屋12 天前
【Unity UI资源包】GUI Pro - Casual Game 专为休闲手游打造的专业级UI资源包
ui·unity
冰凌糕12 天前
Unity3D Shader 顶点法线外扩实现描边效果
unity
小菱形_12 天前
【Unity】TimeLine
unity·游戏引擎
小贺儿开发13 天前
Unity3D 自动化物流分拣模拟
运维·科技·unity·自动化·人机交互·传送带·物流分拣
EQ-雪梨蛋花汤13 天前
【3D可视化】基于 Unity 的智慧体育馆三维信息可视化大屏实践
3d·unity·信息可视化