So I have been trying to write a script that makes footstep sounds when walking, but I have encountered a problem. If you trigger all the buttons in the method I have done (W A S and D) then if you release one of the buttons the stepping sound stops - but you’re still walking because you kept another button pressed down. (Holding W and D down to walk side ways, release D to walk forward but walking sound stops)
Here is the script
#pragma strict
var Sound : AudioClip;
function Start () {
}
function Update () {
if(Input.GetKeyDown("w")){
audio.clip = Sound;
audio.Play();
}
if(Input.GetKeyUp("w")){
audio.Stop();
}
if(Input.GetKeyDown("a")){
audio.clip = Sound;
audio.Play();
}
if(Input.GetKeyUp("a")){
audio.Stop();
}
if(Input.GetKeyDown("s")){
audio.clip = Sound;
audio.Play();
}
if(Input.GetKeyUp("s")){
audio.Stop();
}
if(Input.GetKeyDown("d")){
audio.clip = Sound;
audio.Play();
}
if(Input.GetKeyUp("d")){
audio.Stop();
}
}
`
`