行业知识
Unity 动画(旧版-新版)
2026-11-09 18:18:09
来源:互联网转载
旧版
���版-动画组件:Animation
窗口-动画
动画文件后缀: .anim
将制作后的动画拖动到Animation组件上
旧版的操作
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().Play("r1"); } }} 新版
新版动画组件:Animator
控制器需要在项目中创建:动画控制器
双击新建动画控制器
点击场景中的物体,点击窗口-动画,使用"动画"开始制作2个动画
运行时
鼠标左键点击播放动画1,右键点击播放动画2.
代码实现
using System.Collections;using System.Collections.Generic;using UnityEngine;public class c2 : MonoBehaviour{ private Animator animator; void Start() { // 获取动画器组件 animator = GetComponent(); } // Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { animator.Play("r2"); } if (Input.GetMouseButtonDown(1)) { animator.Play("r1"); } }}