Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Animation states from an Animator in Unity3d

I've used Animator to create two animation states, I want to change the speed of these animations at run type. How can I get these animations at run time and change their speed? Do I have to attach Animation component or Animator is enough?

enter image description here

enter image description here

like image 699
Avraam Mavridis Avatar asked Mar 30 '14 18:03

Avraam Mavridis


1 Answers

Use GetCurrentAnimatorStateInfo() to get current state info.

"Base Layer" is your base layer's name

var currentState : AnimatorStateInfo = animator.GetCurrentAnimatorStateInfo(0);
if (currentState.nameHash == Animator.StringToHash("Base Layer.Player_standing"))
{
    Debug.Log("I'm standing");
}
like image 51
Verv Avatar answered Oct 03 '22 06:10

Verv