- Home /
audio.Play ignoring WaitForSeconds
I want the Audio Clip to finish playing before it can play over again. What am I overlooking?
IEnumerator VoiceOver (AudioClip addedClip)
{
bool playing = false;
AudioClip track = addedClip;
if (!playing)
{
playing = true;
Debug.Log (playing);
audio.PlayOneShot (track);
yield return new WaitForSeconds (track.length);
playing = false;
Debug.Log (playing);
}
}
Comment
Answer by Phantomized · Feb 14, 2015 at 11:20 PM
Your conditional statement "if (!playing)" is right after you declare the bool playing and set it to false. So the condition check will always be true. Try making "playing" a field variable outside the method instead.
Answer by Firedan1176 · Feb 14, 2015 at 11:10 PM
You could use AudioSource.isPlaying() to check if the audio source is playing a clip already, instead of having to do it yourself.
It may be more work to add an audio source, but it is a solution.