Fade, Then Stop all other audiosources attached to gameobject?

I have a script that has 12 audio sources and 12 audio clips attached to object1 , each audio source is in charge of playing one clip. which clip is played depends upon the animation state of object2 when collided with. The problem is with lots of object2’s colliding into object1, lots of clips are being played that all overlap, it doesn’t sound good. my intention is that when object3 collides with object1, hopefully slightly before object2 does. The current audio source, or rather all audio sources playing fade and then stop before object2 collides, thus removing the overlap. I thought perhaps a coroutine would be a good start, but not sure how to implement it. Help appreciated!

using UnityEngine;
using System.Collections;

public class InstrumentController : MonoBehaviour {
	
	public AudioSource[] audios;

	private AudioSource sourceA;
	private AudioSource sourceASharp;
	private AudioSource sourceB;
	private AudioSource sourceC;
	private AudioSource sourceCSharp;
	private AudioSource sourceD;
	private AudioSource sourceDSharp;
	private AudioSource sourceE;
	private AudioSource sourceF;
	private AudioSource sourceFSharp;
	private AudioSource sourceG;
	private AudioSource sourceGSharp;



	void Start()
	{

		audios = GetComponents<AudioSource> ();
		
		sourceA = audios [0];
		sourceASharp = audios [1];
		sourceB = audios [2];
		sourceC = audios [3];
		sourceCSharp = audios [4];
		sourceD = audios [5];
		sourceDSharp = audios [6];
		sourceE = audios [7];
		sourceF = audios [8];
		sourceFSharp = audios [9];
		sourceG = audios [10];
		sourceGSharp = audios [11];

		
	}

	IEnumerator FadeAudio ()
	{

	}
	
	


	void OnTriggerEnter2D(Collider2D col)
	{
		//object2 collisions
		if (col.gameObject.tag == "notecollider" && col.GetComponentInParent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Rednote"))
		{
			sourceB.Play();
		}
		if (col.gameObject.tag == "notecollider" && col.GetComponentInParent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Bluenote"))
		{
			sourceC.Play();
		}
		if (col.gameObject.tag == "notecollider" && col.GetComponentInParent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Bluepurplenote"))
		{
			sourceCSharp.Play();
		}
		if (col.gameObject.tag == "notecollider" && col.GetComponentInParent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Purplenote"))
		{
			sourceD.Play();
		}
		if (col.gameObject.tag == "notecollider" && col.GetComponentInParent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Greypurplenote"))
		{
			sourceDSharp.Play();
		}
		if (col.gameObject.tag == "notecollider" && col.GetComponentInParent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Greynote"))
		{
			sourceE.Play();
		}
		if (col.gameObject.tag == "notecollider" && col.GetComponentInParent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Yellownote"))
		{
			sourceF.Play();
		}
		if (col.gameObject.tag == "notecollider" && col.GetComponentInParent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Yellowgreennote"))
		{
			sourceFSharp.Play();
		}
		if (col.gameObject.tag == "notecollider" && col.GetComponentInParent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Greennote"))
		{
			sourceG.Play();
		}
		if (col.gameObject.tag == "notecollider" && col.GetComponentInParent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Greenorangenote"))
		{
			sourceGSharp.Play();
		}
		if (col.gameObject.tag == "notecollider" && col.GetComponentInParent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Orangenote"))
		{
			sourceA.Play();
		}
		if (col.gameObject.tag == "notecollider" && col.GetComponentInParent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Pinkorangenote"))
		{
			sourceASharp.Play();
		}


}
}


		//object3 collisions
		if (col.gameObject.tag == "note" && col.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Rednote"))
		{
			StartCoroutine(FadeAudio());
		}
		if (col.gameObject.tag == "note" && col.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Bluenote"))
		{
			StartCoroutine(FadeAudio());
		}
		if (col.gameObject.tag == "note" && col.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Bluepurplenote"))
		{
			StartCoroutine(FadeAudio());
		}
		if (col.gameObject.tag == "note" && col.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Purplenote"))
		{
			StartCoroutine(FadeAudio());
		}
		if (col.gameObject.tag == "note" && col.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Greypurplenote"))
		{
			StartCoroutine(FadeAudio());
		}
		if (col.gameObject.tag == "note" && col.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Greynote"))
		{
			StartCoroutine(FadeAudio());
		}
		if (col.gameObject.tag == "note" && col.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Yellownote"))
		{
			StartCoroutine(FadeAudio());
		}
		if (col.gameObject.tag == "note" && col.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Yellowgreennote"))
		{
			StartCoroutine(FadeAudio());
		}
		if (col.gameObject.tag == "note" && col.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Greennote"))
		{
			StartCoroutine(FadeAudio());
		}
		if (col.gameObject.tag == "note" && col.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Greenorangenote"))
		{
			StartCoroutine(FadeAudio());
		}
		if (col.gameObject.tag == "note" && col.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Orangenote"))
		{
			StartCoroutine(FadeAudio());
		}
		if (col.gameObject.tag == "note" && col.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName ("Pinkorangenote"))
		{
			StartCoroutine(FadeAudio());
		}

    }
}
  1. Incase you don’t need fade effect.

    One quick solution is attach single audiosource. Everytime you collide, assign the particular audioClip to the audioSource and then play Audio.

  2. Otherwise if you want fade effect. You’ll need AudioMixer.
    Here a decent Tutorial.