Animation Walk

Hey guys, how are you?
I’m beginner in Unity’s Scripting (JS),
and I have a little question.

I want to do a walking script (I don’t really know how)…
But I want to do this: When I’m walking, an animation will play (“Walk”), and when I stop walking, the animation will stop.
How can I do that?

Thanks guys!
Yours,
Orel Lazri.

You should first make your script handling all the movement. Once you have that, it will just be a matter putting the animation[“Walk”].play(); on the right places in your script ^^

Like this?:

function Update() {
    if (Input.GetButtonDown("Fire1")) {
        transform.position.x += 5;
        animation["Walk"].play();
    }
}

And how can I do when stop walking, the animation will stop?

animation.Stop();