Character Animation Setup

版本检查: 5.2


难度: 新手

In this session, we will look at the basic steps needed to import and setup a rigged character in Unity's animation system.

Character Animation Setup

新手 Animation

Code snippet

using UnityEngine;

public class LocomotionSMB : StateMachineBehaviour
    public float m_Damping = 0.15f;

    private readonly int m_HashHorizontalPara = Animator.StringToHash ("Horizontal");
    private readonly int m_HashVerticalPara = Animator.StringToHash ("Vertical");

    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        float horizontal = Input.GetAxis ("Horizontal");
        float vertical = Input.GetAxis ("Vertical");

        Vector2 input = new Vector2(horizontal, vertical).normalized;

        animator.SetFloat(m_HashHorizontalPara, input.x, m_Damping, Time.deltaTime);
        animator.SetFloat(m_HashVerticalPara, input.y, m_Damping, Time.deltaTime);