- Home /
Play 2 audio's one after another
Hi,
I can't seem to figure out why 2 sounds do not play one after another. Only the first one plays and the second does not. I have set each of my sounds on a game object. The bit of my code is as follows:
if (hasPlayed == false)
{
DieSound.Play();
hasPlayed = true;
if (hasPlayed == true)
{
FalldownSound.Play();
}
}
Where am I going wrong?
Load them in to the AudioClip, then play the clip.
One after another.
Im not quite sure what you mean by loading them in to the AudioClip
Answer by screenname_taken · Jun 07, 2014 at 10:38 PM
Take them out of update and into their own function.
Make an array of two audio clips, load the first one and play it, and right after the call to play it use "yield WaitForSeconds(audio.clip.length);" and right after that load the second clip and play that.
Answer by Tanshaydar · Jun 04, 2014 at 12:39 AM
You can't play to sounds at once at one AudioSource. You need to play then one after another, or play them at different sources. If you want to do former, here it is:
in Awake
bool hasPlayed_1 = false;
bool hasPlayed_2 = false;
in Update
if ( !hasPlayed_1) {
DieSound.Play();
hasPlayed_1 = true;
}
if ( hasPlayed_1 && !hasPlayed_2 && !audio.isPlaying) {
FalldownSound.Play();
hasPlayed_2 = true;
}
If you have two different audio sources, then well, you can just get rid of the audio.isPlaying part and it will do the trick.
This seems to play the sounds at the same time, or its so quick it sounds like they do
Updated the function, sorry, I forgot to add a variable to if clause.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Photon help for a noob! 0 Answers
Proper walk sound / audio play script c# 1 Answer
How to make my machinegun echo? 3 Answers