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;
}
}
}