从Unity3d中的Animator获取动画状态

时间:2014-03-30 18:21:14

标签: animation unity3d

我已经使用Animator创建了两个动画状态,我想在运行类型中更改这些动画的速度。如何在运行时获取这些动画并更改速度?我必须附加动画组件或Animator就够了吗?

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:4)

使用GetCurrentAnimatorStateInfo()获取当前状态信息。

“基础图层”是您的基础图层名称

var currentState : AnimatorStateInfo = animator.GetCurrentAnimatorStateInfo(0);
if (currentState.nameHash == Animator.StringToHash("Base Layer.Player_standing"))
{
    Debug.Log("I'm standing");
}

答案 1 :(得分:0)

//get animation:

animator = GetComponent<Animator>();
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);

//get animation speed, add animation speed

Debug.Log("StateInfo length:  "+stateInfo.length);

if(Input.GetKeyDown(KeyCode.A))
{
    animator.speed += 1f;
}