fadeOut actual music for change it

Hi. I’m trying make a fadeOut function for change the music. So when a function changeMusic() is called, fadeOut the volumen from the actual music playing, and change the clip and play it the new music. Is any way for make the call function be called x times before continue the script and change the music.

using UnityEngine;
using System.Collections;

public class bgMusic : MonoBehaviour {

	public AudioSource bg;
	
	public AudioClip[] music;
	public AudioClip[] battle;
	
	// Use this for initialization
	void Start () {

		int ran = Random.Range (0, music.Length);
		bg.clip = music [ran];
		bg.Play();

	}

	public void changeMusicToBattle(){

		fadeOut ();

		bg.Stop ();
		//int ran = Random.Range (0, battle.Length);
		bg.clip = battle [0];
		bg.Play();

	}

	void fadeOut(){
		if(bg.volume > 0.1f)
		{
			bg.volume -= 0.1f * Time.deltaTime;
		}
	}
}

You could make it an IEnumerator and then wait until it is done fading:

     IEnumerator fadeOut(){
         isDone = false;
         while (bg.volume != 0) {
             if(bg.volume > 0.1f)
             {
                 bg.volume -= 0.1f * Time.deltaTime;
             }
         }
         isDone = true;
     }

     bool isDone = false;

     public void ChangeMusic() {
         StartCoroutine(CM());
     }

     IEnumerator CM(){
 
         StartCoroutine(fadeOut ());
         while (!isDone) {
             yield return null;
         }

         bg.Stop ();
         //int ran = Random.Range (0, battle.Length);
         bg.clip = battle [0];
         bg.Play();
 
     }