How can i play an animation only when i am walking

I was wondering how to play an animation only when i am moving. I have this script to get the animations from the legs:

function BeginAnimation () 
{     
    var animationComp : Animation[] = GetComponentsInChildren(Animation);     
    for (var animComp : Animation in animationComp) 
    {         
              animComp.Play("left leg animation");
             animComp.Play("right leg animation");
    }
}

I was wodering how to script that

Hmmm.......

well you can try

}if(animation["walk"].enabled == true){
    //do something;

or you can use

if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1){
        //do something;

1st of all its not a good idea to do a seperate animation for left and right leg it will be a ballache to make smooth and blend with your run or jump or whatever.

you must go into your player controller and check if you are grounded and if you are moving... then turn a boolean on if you are..

so if (walking) {

animation.Play(Walk);

}

else {

animation.Play(Idle);

}

an easier way would be to say if(Input.GetKeyDown("w)"){

Walk();

}

you would have to repeat for a,s,d

: any walk sounds will work in the same function