How do I play simultaneous sounds one at a time?

I’ve been at this for days and cannot figure it out.

I have a multikill system that plays a sound as you get each multikill. The problem is when you get too many too fast the sound plays over or cuts the sound prior. I’ve tried using wait for seconds, wait for audio length, and isplaying. Sometimes it kind of works but the timing of the sound is off by a few seconds. I need each sound to play first then wait.

Is there anyway to play each sound only after the one prior has finished playing?

Here’s my code, can someone please tell me what I’m doing wrong.

This is in C#

IEnumerator MultiKills() {

             //Wait for multiKill2 sound then play multiKill3 sound
		 if (!audio.isPlaying) {
			audio.clip = multiKill3Sound;
			yield return new WaitForSeconds(multiKill2Sound.length);
            audio.Play();    		
		    }

         if (multiKill == 3) { //Or this?
    			audio.clip = multiKill3Sound;
    			yield return new WaitForSeconds(multiKill2Sound.length);
                audio.Play();    		
    		}
}

//Multikill 3 happens
if (multiKill == 3)
   {
      StartCoroutine(MultiKills())
   }

How does this do for you? I’m not 100% on my C#-Coroutine syntax, but the logic should work.

I’m thinking in your original code that you’re triggering Sound1 at 0 seconds, and it’s 2 seconds long. Then Sound2 triggers at one second, but then it waits for 2 seconds (instead of the one it should wait for).

private List<AudioClip> queue;

void Start() { 
  queue = new List<AudioClip>();
  StartCoroutine(AudioCorou());
}

/*whatever type Coroutines require*/ AudioCorou() {
  while ( 1 ) {
    if ( queue.Count > 0 ) {
      audio.clip = queue[0];
      audio.Play();
      yield return new WaitForSeconds( queue[0].length );
      queue.RemoveAt(0);
    } 
    yield;
  }
}
void PlaySound( clip : AudioClip ) { queue.Add(clip); }

If you want to get away from the constant-yield coroutine, you could set it up to only play while queue’s not empty, and then when you add an element to empty queue, start the coroutine then (instead of in Start).

`
/something like this?/

public AudioClip multiKill3;
boolean queuedMultiKill3;
public AudioClip multiKill5;
boolean queuedMultiKill5;

void Start() {
queuedMultiKill3 = false; queuedMultiKill5 = false;
}

void Update() {
if(!audio.isPlaying){
if(queuedMultiKill3){
queuedMultiKill3 = false;
audio.PlayOneShot(multiKill3);
}else if(queuedMultiKill5){
queuedMultiKill5 = false;
audio.PlayOneShot(multiKill5);
}
}
}
`