How do I stop footstep sound from playing when I release 'w'?

Okay basically I’m trying to write a script that plays an audio clip on loop when I move, but when i take my finger off the w/forwards key, the clip still keeps playing. I’m totally new to scripting and unity so i’m not too sure how to sort this out, i was thinking i’d have to make another piece of script where audio.loop = false but not sure how to do it. any ideas?

    var AudioFile : AudioClip;

function Update() {

    if (Input.GetKeyDown (KeyCode.W))
    {
    audio.clip = AudioFile;
    audio.loop = true;
    audio.Play();
     
    }

}

ok, See how you made it loop? you don’t want that on when w is released, just use an else block and set audio.loop back to false. you could also make if(!Input.GetKeyDown(keycode.W)) which is the opposite of if (Input.GetKeyDown (KeyCode.W))

else {
audio.loop = false;
}

//or 

else if((!Input.GetKeyDown(keycode.W)) {

audio.loop = false;

}

be sure to check the tutorials Unity offers as well as its documentation