When in play mode, i press W and it exits play mode?

I found a script from a tutorial on YouTube, and it was to make a walking animation play when I pressed W. I went into play mode, and the animation was already playing and when I press W, it exits game mode. Why does this happen? How can I fix it? Here is the script:

   function Update()
{
 if(Input.GetKeyDown("w"))
 {
  // Plays the walk animation animation - stops all other animations
  animation.Play("walk animation", PlayMode.StopAll);
 }
}

Chances are that you have an error and that you have pause on error set in your console like this:

[26235-screen+shot+2014-05-06+at+12.09.57+pm.png|26235]

Click Error Pause to turn that off.

HOWEVER it wouldn’t be an issue if you didn’t have an error, so find the error as your first step.

Given that you blindly copied this script, my first guess would be that your animation is not named “walk animation”, but thats just a guess.