How can I get the legnth of an animation? (Mechanim Animator/C#)

I’m making a First Person Shooter, and I’m currently trying to get my gun to reload, but I want to make the game wait until the reload animation has finished before the player can shoot again, I’m having trouble with this.

I am using the Mechanim Animator to do my animations, but all the solutions I see use the regular animation component.

I would think that you use “WaitForSeconds”, the problem is, I don’t have the value for the WaitForSeconds to wait for.

So how would I get the legnth of an animation when I’m using the mechanim animator? Preferably in C#.

I dont know wheather you can get animation lenght, but you dont really need to know it. You should have different animation/gameplay states. Eg. (ready, reloading, jumping,…).

static int reloading = Animator.StringToHash("Base.Reloading");
//Base - layer name; Reloading - animator state name

Then based on your animator state you decide wheather you can shoot or not. Animator will make shure your state gets to ready after reloading animation is finnished (exit-time).

I would weapon animations on separate layer than movement etc.

Animator anim;
void Start (){
    anim = GetComponent<Animator>();               

void FixedUpdate ()
    currentBaseState = anim.GetCurrentAnimatorStateInfo(0); //if your stuff is on 1st layer

    if (currentBaseState.nameHash == reloading){

to get the length of the current state: yourAnimatorVariable.GetCurrentAnimatorStateInfo(0).length

0 if it the first layer, 1 if it’s the second, etc