using UnityEngine;
using System.Collections;


public class MusicManager : MonoBehaviour {
    public static MusicManager instance;

    public AudioSource audioSource;
    public AudioClip introMusic;
    public AudioClip fireMusic;
    public AudioClip waterMusic;
    public AudioClip successMusic;
    public AudioClip failMusic;

    private void Awake() {
        instance = this;
    }

    public void PlayIntroMusic() {
        PlayMusic(introMusic);
    }

    public void PlayForceMusic(ForceType force) {
        if (force == ForceType.Fire) {
            PlayMusic(fireMusic);
        } else if (force == ForceType.Water) {
            PlayMusic(waterMusic);
        } else {
            audioSource.Stop();
        }
    }

    public void StopMusic() {
        audioSource.Stop();
    }

    public void PlaySuccessMusic() {
        AudioSource.PlayClipAtPoint(successMusic, Camera.main.transform.position);
        PlayIntroMusic();
    }

    public void PlayFailMusic() {
        PlayMusicOnce(failMusic);
    }

    private void PlayMusic(AudioClip music) {
        audioSource.clip = music;
        audioSource.Stop();
        audioSource.Play();
    }

    private void PlayMusicOnce(AudioClip music) {
        audioSource.clip = music;
        audioSource.Stop();
        audioSource.PlayOneShot(music);
    }

}
