Random footstep sounds not looping

Hi there,

I’m having an issue where a script I have is supposed to loop randomly between four different footsteps sounds when forward is pressed. The problem is that when ‘W’ is pressed, it plays one of the four clips at random, but won’t loop until I release ‘W’ and press it again.

Any help is appreciated!

#pragma strict

var Steps : AudioClip[];

function Update() {

	if (Input.GetKeyDown(KeyCode.W))
	{
    	audio.clip = Steps[Random.Range(0,Steps.length)];
    	audio.loop=true;
    	if (!audio.isPlaying)
    	{	
    		audio.Play();
    	}
	}
	else (!Input.GetKeyDown(KeyCode.W))
	{
		audio.loop=false;
	}
}

I solved the issue:

function Update() {

	if (Input.GetKeyDown(KeyCode.W))
	{
    	audio.clip = Steps[Random.Range(0,Steps.length)];
    	audio.loop=true;
    	if (!audio.isPlaying)
    	{	
    		audio.Play();
    	}
	}
	if (Input.GetKeyUp(KeyCode.W))
	{
    	audio.Stop();
 	}


}