How to stop all audio except one in C#?

Hi guys!

As the title says I’m wondering how to stop all audio from playing except one. Right now I have a trigger that starts the sound I want to play alone. All other sounds are playing as well though. So how do I stop them?

This is the code that solved this:

void OnTriggerEnter(Collider coll)
{
    triggerEntered = true;
    if (coll.gameObject.tag == "Player")
    {
       AudioSource[] audios = FindObjectsOfType(typeof(AudioSource)) as AudioSource[];
       foreach(AudioSource aud in audios)
         aud.volume = 0;

         audio.volume = 1;
         audio.Play ();
    }
}

Basically in the script, have audio.Stop() and in the parenthesis’s have the Audio File name.

Do this to all the sounds that you want to stop.

That’s one way :3

If you need a script, I can probably make one up for you

Take Care

-Squizy