using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;

public class AudioPlayerController : MonoBehaviour
{
    [SerializeField] AudioMixer Mixer;
    [SerializeField] AudioSource Source;
    public Dictionary<string, AudioClip> AudioClips;

    private void Awake()
    {
        var objs = FindObjectsOfType<AudioPlayerController>();
        if (objs.Length > 1)
        {
            DestroyImmediate(this.gameObject);
        }
        else
        {
            DontDestroyOnLoad(this.gameObject);

            AudioClips = new Dictionary<string, AudioClip>();
            var clips = Resources.LoadAll<AudioClip>("Sounds");
            foreach (var cl in clips)
            {
                AudioClips[cl.name] = cl;
            }
        }
    }

    public void PlayClip(string name)
    {
        Source.PlayOneShot(AudioClips[name]);
    }

    void Start()
    {

    }

    void Update()
    {

    }
}
