Get animated states from an animator in Unity3d

I used Animator to create two states of animation, I want to change the speed of these animations at startup. How can I get these animations at runtime and change their speed? Do I need to attach an Animation or Animator component?

enter image description here

enter image description here

+4
source share
2 answers

Use GetCurrentAnimatorStateInfo () to get current status information.

"Base Layer" is the name of your base layer

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

Source: https://habr.com/ru/post/1534147/


All Articles