第一步创建动画层
第二步添加遮罩Avatar Mask
第三步设置权重
模型上的源码:
using UnityEngine;
using System.Collections;
public class AvatarMaskTest : MonoBehaviour {
private Animator m_animator;
// Use this for initialization
void Start () {
m_animator = this.GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.R))
{
m_animator.SetBool("run",true);
}
if (Input.GetKeyUp(KeyCode.R))
{
m_animator.SetBool("run", false);
}
if (Input.GetKeyDown(KeyCode.J))
{
m_animator.SetBool("jump", true);
}
if (Input.GetKeyUp(KeyCode.J))
{
m_animator.SetBool("jump", false);
}
if (Input.GetKeyDown(KeyCode.W))
{
m_animator.SetBool("wave", true);
}
if (Input.GetKeyUp(KeyCode.W))
{
m_animator.SetBool("wave", false);
}
}
}
动画效果: