Getting the length of an animation

So hey guys, i’m trying to implement some melee with animation.

        if(target != null && target.name == "Player"){
            baseMeleeTimer -= Time.deltaTime;

            float dist = Vector3.Distance(target.position, myTransform.position);
            if(dist > 1.0f && dist < 3.9f){
                //Debug.Log("We can attack" + dist);
                //baseMeleeTimer -= Time.deltaTime;
                Debug.Log(baseMeleeTimer);
                if(baseMeleeTimer < meleeResetTimer){
                    Debug.Log("Attack");
                    Debug.Log(baseMeleeTimer);
                    MeleeAttack();
                }
            }

        }

So basically, if the player is targeted the timer ticks down. If the player is in that ditance, and the baseMeleeTimer is less than 0, then it goes to the MeleeAttack();

    private void MeleeAttack(){
        Debug.Log("Attacking");
        if(animation.IsPlaying("idle"))
        {
            //Debug.Log("Dont play");
            animation.Stop("idle");
            animation.Play("attack3");
            if(animation["attack3"].length > 1.0f){
                //Debug.Log("Stop attacking");
                animation.Stop();
            }
        }
    }

now I check to see if idle is playing. If is then I stop this animation and play the attack animation.

NOW HERE - i want to check if that animation has stopped playing. If it has, then I’ll stop the animation and set the timer back to 0 , and do some collision testing (god help me).

So the question is, is there a method where it can return the length of an animation so I can use it in my “If” statement.

Thank you for your time.

animation[“name”].clip.length might be what you’re looking for?
clip is an AnimationClip object - Unity - Scripting API: AnimationClip