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()
  // 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:


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.