How do i play two sounds at same time?

I’m using this script to play audio in the update method:

void Update(){
if(counter < 5)
counter++;
if(counter >= 5){
ASources[0].Play();
counter = 0;
}
}

I want the sound to play even if the previous sound is still playing, but instead it just stops the previous one to play the new one how do i fix this?

Use “PlayOneShot”

That does not stop the audio that is already playing

5 Likes

Yes, but there’s a downside to PlayOneShot. After you start a sound playing that way, you lose control over stopping it, changing the volume / pitch etc. You can only stop / change volume of ALL the one-shots at once. So for long sound effects, I find it unusable. Sometimes it’s preferable to use multiple game objects all with their own Audio Source & Clip.

4 Likes

Thanks for your help, it worked.

1 Like

It’s just a quick gun shot nothing long, so this wouldn’t be a problem for me, but thanks for the tip.

thanks for sharing

Thanks!

oneShot is doing exactly that for me. No matter what I do it stops the audio already playing even though they have different audio sources! somebody please help!

I am not really sure If I understand your problem, but you should try AddComponent for each clip like this:

    public void PlaySound(string soundName, float volume) // VOLUME IS 0 - 1
    {
        for (int i = 0; i < clips.Length; i++)
        {
            if (clips[i].name.ToUpper() == soundName.ToUpper())
            {
                AudioSource source_ = gameObject.AddComponent<AudioSource>();
                Destroy(source_, 5);
                source_.clip = clips[i];
                source_.volume = volume;
                source_.Play();
                InstantiateSoundSphere(volume);
            }
        }
    }