首页 文章

从Unity3d中的Animator获取动画状态

提问于
浏览
5

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

enter image description here

enter image description here

2 回答

  • 4

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

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

    var currentState : AnimatorStateInfo = animator.GetCurrentAnimatorStateInfo(0);
    if (currentState.nameHash == Animator.StringToHash("Base Layer.Player_standing"))
    {
        Debug.Log("I'm standing");
    }
    
  • 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;
    }
    

相关问题