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");
        }
    }
}
相关推荐
lingxiao1688815 分钟前
WebApi详解+Unity注入--中篇:.net core的WebAPI
unity·c#·.netcore
weixin_423995003 小时前
unity 处理图片:截图,下载,保存
java·unity·游戏引擎
呆呆敲代码的小Y7 小时前
【Unity实战篇】| 游戏轮播图效果,多种实现思路及完整教程
游戏·unity·游戏引擎·实战·游戏开发·轮播图·u3d
示申○言舌9 小时前
Unity高性能参数差异化URP Shader圆角圆环UI进度条
ui·unity·游戏引擎·圆环进度条·参数差异化·材质参数独立·圆角圆环
一只一只21 小时前
Unity之协程
unity·游戏引擎·协程·coroutine·startcoroutine
NIKITAshao1 天前
Unity 跨项目稳定迁移资源
unity·游戏引擎
sindyra1 天前
Unity资源内存管理与释放
unity·游戏引擎·资源管理·资源释放·内存释放
CreasyChan1 天前
Unity FairyGUI高斯模糊实现方法
unity·游戏引擎·fgui
avi91111 天前
Unity半官方的AssetBundleBrowser插件说明+修复+Reporter插件
unity·游戏引擎·打包·assetbundle·游戏资源
郝学胜-神的一滴1 天前
深入理解Mipmap:原理、实现与应用
c++·程序人生·unity·游戏程序·图形渲染·unreal engine