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");
        }
    }
}
相关推荐
阿赵3D31 分钟前
Unity引擎播放HLS自适应码率流媒体视频
unity·游戏引擎·音视频·流媒体·hls
NRatel3 小时前
Unity 游戏提升 Android TargetVersion 相关记录
android·游戏·unity·提升版本
SmalBox5 小时前
【渲染流水线】[光栅阶段]-[片元着色]以UnityURP为例
unity·渲染
★YUI★1 天前
学习游戏制作记录(玩家掉落系统,删除物品功能和独特物品)8.17
java·学习·游戏·unity·c#
SmalBox1 天前
【渲染流水线】[光栅阶段]-[光栅插值]以UnityURP为例
unity·渲染
谷宇.1 天前
【Unity3D实例-功能-拔枪】角色拔枪(二)分割上身和下身
游戏·unity·c#·游戏程序·unity3d·游戏开发·游戏编程
NRatel2 天前
亚马逊S3的使用简记(游戏资源发布更新)
游戏·unity·amazon s3
SmalBox2 天前
【渲染流水线】[几何阶段]-[屏幕映射]以UnityURP为例
unity·渲染
SmalBox3 天前
【渲染流水线】[几何阶段]-[归一化NDC]以UnityURP为例
unity·渲染
SmalBox4 天前
【渲染流水线】[几何阶段]-[图元装配]以UnityURP为例
unity·渲染