Stop animation if no key is pressed

hi all, I want to make my character walk when I press the w key, and I did it . but when I stop pressing the w key, the animation keeps playing… this is my code

function Start ()
{
this.animation.wrapMode = WrapMode.Loop;
}
function Update()
{
if(Input.GetKeyDown(“w”))
{
animation.Play(“Take 001”);
if(Input.anyKey == false)
{
animation.Stop(“Take 001”);
}
}
}

I would like someone help me…

Your stop animation invoker is within the Input.GetKeyDown(“w”) scope which pretty much ensures it will never execute. Try with this:

var animationPlaying = false;

function Update() {
  if(Input.GetKeyDown("w")) {
    if(!animationPlaying) {
      animation.Play("Take 001");
      animationPlaying = true;
    }
  } else if(animationPlaying) {
      animation.Stop("Take 001");
      animationPlaying = false;
  }
}