using UnityEngine;
using System.Collections;

public class AudioController : MonoBehaviour {

	[SerializeField] protected AudioSource soundSource;

	[SerializeField] protected AudioClip[] soundTracks;
	[SerializeField] protected AudioSource[] musicTracks;

	private int intensity = 0;
	private int[] selectedTracks;


	public void Start()
	{
		selectedTracks = new int[] { 0, 1, 2 };
		StartCoroutine (RefreshMusicLoop());
	}

	public IEnumerator RefreshMusicLoop()
	{
		intensity = (intensity + 1) % 3;
		musicTracks [selectedTracks [intensity]].mute = true;
		yield return new WaitForSeconds (32);
		int index = Random.Range (0, 2) + (intensity*3);
		selectedTracks [intensity] = index;
		musicTracks [index].mute = false;
	}
		
	public void PlaySoundFX(int index)
	{
		soundSource.Stop ();
		soundSource.clip = soundTracks [index];
		soundSource.Play ();
	}
}
