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

[RequireComponent(typeof(AudioSource))]
public class BackgroundAudio : MonoBehaviour {

	[SerializeField] List<AudioClip> tracks;

	private int currentTrack = 0;

	void PlayCurrentTrack()
	{
		audio.clip = tracks[currentTrack];
		audio.Play ();
	}

	// Use this for initialization
	void Start () {
		PlayCurrentTrack();
	}
	
	// Update is called once per frame
	void Update () {
		if(!audio.isPlaying)
		{
			if(currentTrack < tracks.Count-1)
				currentTrack++;
			else
				currentTrack=0;

			PlayCurrentTrack();
		}


	}
}
