Unity Animator BlendTree
创建 Animtor Controller 命名为 BlendTreeController, 双击打开
空白处鼠标右键 Create State -> From New Blend Tree
默认名为 Blend Tree,选择 Blend Tree 查看 Inspector 面板
将 混合树名字修改为 RunTree 其他参数默认
此时 Animator Controller 窗口中 BlendTree 修改名
双击 RunTree 进入 编辑界面
Inspector 面板如下
下面编辑 Blend Tryp = 1D,即只有一个变量操作变化
添加动画文件, 点击 + -> Add Motion Field
连续添加3次如下
将动画文件拖拽至 Motion 处
动画文件将自动显示在编辑窗口
Inspector 面板
Threshold 的值即为切换三个动画的参数Blend 的值(Blend 系统默认添加的,一般不使用它)
当 Blend = 0 时,切换到 第一个动画
当 Blend = 0.5 时,切换到第二个动画
当 Blend = 1 时,切换到第三个动画
创建自己的 Parameter
重新选择控制参数
将模型拖拽到场景,将 BlendTreeController 拖拽给模型Animator
运行 Unity,播放动画
双击打开 RunTree ,蓝色线为当前播放动画,修改 RunDir 的值
切换到不同动画
代码控制如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
private Animator animator;
// Use this for initialization
void Start () {
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.A))
{
animator.SetFloat("RunDir", 0);
}
if (Input.GetKeyDown(KeyCode.D))
{
animator.SetFloat("RunDir", 0.5f);
}
if (Input.GetKeyDown(KeyCode.S))
{
animator.SetFloat("RunDir", 1);
}
}
}