Play Animation while Button is pressed

Hi I implemented a 3D Char into my Unity project and finally managed to get the animations playing, however the run animation just play once as soon as I press the forward button.
What I want is that as long as the forward Button is being pressed the animation should play and not just once.

Can someone help me with this ?!

var walking = false;

function Update () {

if (Input.GetAxis(“Horizontal”) > 0.2 && !walking) {

  animation.CrossFade ("walk");

    walking = true;
} 

if (Input.GetAxis("Horizontal") <= 0.2 && walking) {

    animation.CrossFade ("idle");

    walking = false;

}

Why not do it much simpler?

function Update () {
    if(Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2)
        animation.CrossFade("walk");
    else
        animation.CrossFade("idle");
}

This will make the animation play until the player has stopped walking.

Mathf.Abs returns the absolute value of a float. If you don’t want that you can just remove the “Mathf.Abs” part.