Animation reverse for movement

Here is my code for movement and after press once on "s" key, it works once and then the animation does not work any more even i press "w" key. please help. I want to reverse my animation "walk" from end frame to first frame by pressing "s" key.

function Update()
{
if(Input.GetKey("w"))
{
animation.Play("walk");
transform.Translate(Vector3.forward * Time.deltaTime);
}
else if (Input.GetKey("s"))
{
animation["walk"] = -1.0;
transform.Translate(Vector3.forward * Time.deltaTime * -1.0);
}
}

I still can not find out why your code still does not work.

When playing an animation backwards, not only do you have to set the speed to negative, but you have to set the time of the animation to the end of the animation rather than the start. Like so:

animation["walk"].speed = -speed;
animation["walk"].time = animation["walk"].length;
animation.Play("walk");

When you play the animation forwards, you might want to try setting the time value to zero, so it will play from the start.

animation["walk"].speed = speed;
animation["walk"].time = 0;
animation.Play("walk");

You may also want to use animation.CrossFade("walk") rather than Play().

In addition to this correct answer above: If you are going to use animation.PlayQueued() instead of animation.Play() keep in mind that this function “clones” the AnimationState and therefore you have set these values on the cloned state after issuing the PlayQueued command.