- Home /
Question by
temstindoesunity · May 20, 2014 at 02:39 AM ·
javascriptaudiosound on key
How to prevent an audio clip being spammed?
var reload : AudioClip;
function Update (){
if (Input.GetKeyDown("r")) {
audio.PlayOneShot(reload);
}
}
This JavaScript works fine but if you repeatedly press R, it spams the sound and eventually makes a huge audio mess. How do i prevent this?
Comment
try adding && !audio.isPlaying ?
http://docs.unity3d.com/Documentation/ScriptReference/AudioSource-isPlaying.html
Your answer
Follow this Question
Related Questions
Audio loop after time 2 Answers
My Footstep isn't working 2 Answers
A node in a childnode? 1 Answer
Audio is repeating. 3 Answers