Animator操作介绍
-
组件
- Animator
-
项目
- 创建动画控制器
-
窗口
- 创建动画
- 选中要创建动画的物体,创建
*.anim
文件 - 创建属性
-
双击项目中的「创建动画控制器」,可以得到
-
-
可以更改默认执行剪辑
-
-
当通过动画控制器里面访问动画剪辑片段时,检查器里将有更多设置选项
脚本控制
Animator
也是组件,在脚本中类型为Animator
,因此也可以通过GetComponent<T>();
获得。一般音频和动画GetComponent<T>();
常用方法为Play()
,Play()
包含多个重载,其中字符串类型参数,是直接访问视频剪辑名称。
脚本实例
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimatorTest : MonoBehaviour
{
private Animator animator;
void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
animator.Play("Left");
}
}
}