using System;
using UnityEngine;

public class MusicManager : MonoBehaviour
{
    public AudioSource sourceGood;
    public AudioSource sourceBad;


    public event Action<AudioSource> onMusicChanged;
    void Start()
    {
        onMusicChanged?.Invoke(sourceGood);
        // The good version plays first
        sourceGood.mute= false;
        sourceBad.mute = true;

        sourceGood.Play();
        sourceBad.Play();

        GetComponent<BeatClock>()?.StartMusicScheduled();
    }

    public void PlayGoodMusic()
    {
        onMusicChanged?.Invoke(sourceGood);
        
        sourceGood.mute = false;
        sourceBad.mute = true;
    }
    
    public void PlayBadMusic()
    {
        onMusicChanged?.Invoke(sourceBad);
        
        sourceGood.mute = true;
        sourceBad.mute = false;
    }
}
