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

public class AudioManagerScript : MonoBehaviour {

    public SoundClass[] clips;

    public static AudioManagerScript instance;

	// Use this for initialization
	void Awake () {
        if(instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
            return;
        }
        DontDestroyOnLoad(gameObject);

		foreach(SoundClass s in clips)
        {
            s.source = gameObject.AddComponent<AudioSource>();
            s.source.clip = s.clip;

            s.source.volume = s.volume;
            s.source.pitch = s.pitch;
            s.source.loop = s.loop;
        }
	}
	
	public void PlayClip(string name)
    {
        SoundClass s = Array.Find(clips, sound => sound.name == name);
        if (s == null)
        {
            Debug.Log("Sound: " + name + "not found");
            return;
        }
        s.source.Play();
    }
}
