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");
        }
    }
}
相关推荐
Thomas_YXQ1 天前
Unity3D 战斗系统架构与设计详解
开发语言·unity·架构·系统架构·unity3d
Nicole Potter1 天前
内存泄漏指什么?常见的内存泄漏有哪些?
开发语言·游戏·unity·面试·c#
Jditinpc1 天前
Unity FBXExport导出的FBX无法在Blender打开
unity·游戏引擎·blender
太妃糖耶2 天前
Unity地形系统
unity·游戏引擎
别偷喝船长的朗姆酒2 天前
【Unity】鱼群效果模拟
unity·游戏引擎
WarPigs3 天前
Unity汽车笔记
笔记·unity·汽车
奔跑的犀牛先生3 天前
unity学习52:UI的最基础组件 rect transform,锚点anchor,支点/轴心点 pivot
unity
奔跑的犀牛先生3 天前
unity学习53:UI的子容器:面板panel
unity
larito3 天前
HybridCLR+Adressable+Springboot热更
unity·热更
太妃糖耶3 天前
Unity贴图与模型相关知识
unity·游戏引擎·贴图