
var backgroundMusic : AudioClip[];

private var index : int;
private var selectedMusic : AudioClip;

function Start()
{
	index = Random.Range(0, backgroundMusic.Length);
	nextTrack();
}

function Update () 
{
	if (!audio.isPlaying)
	{
		nextTrack();
	}
}

function nextTrack()
{
	index = (index+1) % backgroundMusic.Length;
	selectedMusic = backgroundMusic[index];
	audio.clip = selectedMusic;
	audio.Play();
	print("playing " + selectedMusic.name);
}