using UnityEngine.Audio;
using UnityEngine;

public class GameMusic : MonoBehaviour {
   
    public AudioMixerSnapshot[] snapshots;          
                       
    public AudioMixer mixer;
    public float transitionTime;

    private float[] weights = new float[3];
    private int lastMusicLevel = 0;

    public void ChangeGameMusic (int actualMusicLevel)
    {
        weights[lastMusicLevel] = 0f;
        weights[actualMusicLevel] = 1f;

        mixer.TransitionToSnapshots(snapshots, weights, transitionTime);
        lastMusicLevel = actualMusicLevel;        
    }
}
