- Home /
audio.IsPlaying dosn't work
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 ++;
}
}
Answer by smoggach · Oct 06, 2014 at 08:16 PM
Try using Play instead of PlayOneShot.
PlayOneShot was designed for playing the same sound multiple times from the same source, so I imagine there's some weirdness going on with isPlaying.
Your answer
Follow this Question
Related Questions
Can't get sound clip from array to play properly 1 Answer
IndexOutOfRangeException error 1 Answer
Array index confusion - what does [i-1] do exactly??? 4 Answers
DIALOGUE BRANCH CREATION? 1 Answer
Could you help me with Array.RemoveAt()? 0 Answers