using UnityEngine;
using System.Collections;

public class MusicManager : MonoBehaviour {
	
	private int audioPlaying = 0;
	public AudioClip[] clips;
	private AudioSource ac; 
	
	// Use this for initialization
	void Start () {
		if (GameObject.FindGameObjectsWithTag ("MusicManager").Length > 1) {
			Destroy (gameObject);
		}

		DontDestroyOnLoad(gameObject);
		ac = gameObject.GetComponent<AudioSource>();
		ac.clip = clips[audioPlaying];
		ac.Play();
	}
	
	public int SetTrack
	{
		get
		{
			return audioPlaying;
		}
		set
		{
			if(value != audioPlaying)
			{
				audioPlaying = value;
				if(audioPlaying >= clips.Length)
					audioPlaying = clips.Length - 1;
					
				ac.Stop();
				ac.clip = clips[audioPlaying];
				ac.Play();
			}
		}
	}
	
}
