Hello,
I wrote this script that is supposed to play a sound when you click a door. The problem is that it must prevent the sound to play if the player spams the door, but it doesn’t work. When I click the object, no matter if a sound is already playing, it plays it again…
Any help?
#pragma strict
var soundToPlay : AudioClip[];
var knocks : int;
function Start () {
}
function OnMouseDown () {
if(!audio.isPlaying)
{
var index : int = Random.Range(0,12);
audio.clip = soundToPlay[index];
audio.PlayOneShot(soundToPlay[index]);
knocks ++;
}
}