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();
}
}
thanks so much buddy! i'll try that now to see if it's sorted. Honestly thanks a lot.
– Ross_Dickinsonso should my final script be var AudioFile : AudioClip; function Update() { if (Input.GetKeyDown (KeyCode.W)) { audio.clip = AudioFile; audio.loop = true; audio.Play(); } else if((!Input.GetKeyDown(keycode.W)) { audio.loop = false; } }
– Ross_Dickinsonyeah, you could just use else in this case, (since there's only two possible outcomes). I was just showing you some extra ropes
– Fornoreason1000