旧版
旧版-动画组件:Animation
 窗口-动画
 动画文件后缀: .anim
 将制作后的动画拖动到Animation组件上
 
 旧版的操作
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class c1 : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){if (Input.GetMouseButtonDown(0)){GetComponent<Animation>().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<Animator>();}// Update is called once per framevoid Update(){if (Input.GetMouseButtonDown(0)){animator.Play("r2");}if (Input.GetMouseButtonDown(1)){animator.Play("r1");}}
}