Check If Animator Animation Has Finished

Alright. So, I’ve started learning how to make 2D games. The script below is the basic script that controls the character’s motions and animations. Everything works fine, except for kick. Because kick (indicated by the namesake comment) is a GetKeyDown instead of GetKey, the animation activates, then is immediately canceled by the idle checker (labeled ‘Idle’ below). I also can’t do the same thing I did for the jump motion because I have no way to know when the kick animation has finished. So, my question is: how would I go about making sure that the kick animation has finished playing before it transitions to the idle animation. I hope that was a clear enough explanation. Thanks in advance for the help.

public class Motion : MonoBehaviour {
	Animator anim;
	float moveVel;
	Vector2 dirVec = new Vector2(0,0);
	float jumpVel = 50.0f;
	bool jumping = false;

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

	void Update () {
		//Resets velocity to zero.
		dirVec = Vector2.zero;

		//Jump
		if(Input.GetKeyDown ("space")&&jumping==false)
		{
			transform.rigidbody2D.velocity = new Vector2(dirVec.x, jumpVel);
		}

		//Kick
		if(Input.GetKeyDown ("f"))
		{
			Debug.Log ("Kick.");
			anim.SetInteger ("AnimState", 2);
		}

		//Right
		else if(Input.GetKey ("d"))
		{
			anim.SetInteger("AnimState", 1);
			dirVec.x = 20.0f;
			transform.localScale = new Vector2(1, transform.localScale.y);
		}

		//Left
		else if(Input.GetKey ("a"))
		{
			anim.SetInteger("AnimState", 1);
			dirVec.x = -20.0f;
			transform.localScale = new Vector2(-1, transform.localScale.y);
		}

		//Idle
		else
		{
			anim.SetInteger ("AnimState", 0);
		}

		//Check if character is on ground. Resets jump counter.
		if(Physics2D.Raycast (new Vector2(transform.position.x + 1.15f, transform.position.y), -Vector2.up, 1.38f)||Physics.Raycast (new Vector2(transform.position.x - 1.15f, transform.position.y), -Vector2.up, 1.38f))
		{
			jumping = false;
		}

		else
		{
			jumping = true;
		}

		//Initialize the movement.
		transform.rigidbody2D.velocity = new Vector2 (dirVec.x, transform.rigidbody2D.velocity.y);
	}
}

if (this.animator.GetCurrentAnimatorStateInfo(0).IsName(“YourAnimationName”))
{
// Avoid any reload.
}
you can search question before ask, it’s here