wait until an animation finishes

Hello Unity3D i have a question about animation.How can i make it that when i do an animation you can’t do anything else until animation is finished?For example,when i make my character throw a projectile the idle animation that plays waits for it to finish but when i click the movement keys like up,down,left,right the character still moves.How can i make it that the character plays an animation and you can’t do nothing to stop it until the animation is completely finished?

Use coroutine and bool variable. Idle and Walk animation is loop(write on CSharp):

 private bool state = false;
 private bool change = false;
 private string curAnim = "";

 void Update() {
  //play idle
  if (Input.GetKeyDown(KeyCode.I)) {
   if(curAnim != "Idle") {
    curAnim = "Idle";
    change = true;
   }
  }
  if (Input.GetKeyDown(KeyCode.T)) {
   if(curAnim != "Walk") {
    curAnim = "Walk";
    change = true;
   }
  }
  if(change && !state) {
   this.animation.Play(curAnim);
   this.StartCoroutine(this.myPlay(curAnim));
  }
 }

 public IEnumerator myPlay(string tpAnim) {
  curAnim = tpAnim;
  while(!change) {
   state = true;
   yield return new WaitForSeconds(this.animation.clip.length);
   state = false;
  }
 }

I hope that it will help you.