﻿using UnityEngine;
using System.Collections;

public class MusicManager : MonoBehaviour {

	public AudioClip[] levelMusicChangeArray;

	private AudioSource audioSource;
	// Use this for initialization
	void Awake () {
		DontDestroyOnLoad (gameObject);
	
	}

	void Start () {
		audioSource = GetComponent<AudioSource> ();
		audioSource.volume = PlayerPrefsManager.GetMasterVolume();
		PlayerPrefsManager.SetDifficulty (2f);
		Debug.Log ("Music Manager has set Difficulty to 2");
	}


	void OnLevelWasLoaded(int level) {
		AudioClip thisLevelMusic = levelMusicChangeArray [level];
		//Debug.Log ("Playing audio clip: " + thisLevelMusic);
		if (thisLevelMusic) {
			audioSource.clip = thisLevelMusic;
			audioSource.loop = true;
			audioSource.Play();
		}
	}
	// Update is called once per frame
	void Update () {
	
	}

	public void AdjustVolume(float volume) {
		audioSource.volume = volume;
	}
}
