Play Animator animation then do something

so i have a menu canvas that animates when its activated and when its deactivated its called through a script where the escape key is pressed

how do i make the animator component play an animation then setactive(false);?

this is on the canvas

	public GameObject can;

	public void Disable(){
		can.SetActive (false);
}

one way is using Coroutines use start Coroutine to start the disable function and it will be in that function till animation finishes then it will destroy your game object

 StartCoroutine(Disable());
    
    IEnumerator Disable() {
        animation.Play("fade");
        while (animation.isPlaying) { 
            yield return null;
        }
        Destroy (gameObject);
    }

another way is to add an animation event to last keyframe of your animation

http://docs.unity3d.com/Manual/animeditor-AnimationEvents.html

When you call the animation to play after that start a coroutine that will wait for required seconds and then deactivate the object.

Psuedo-code:

void PlayAnimation()
{
    // You play your animation here
    // Now you call the coroutine
    StartCoroutine("DeactivateObject");

}

IEnumerator DeactivateObject()
{
    yield return new WaitForSeconds(TimeRequiredToPlayAnimation);
    // Deactivate the game object
    gameObject.SetActive(false);
}