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

public class MusicController : MonoBehaviour {
	public List<AudioClip> MusicClipList;
	public AudioSource MusicSource;
	public float minCooldown = 2;
	public float maxCooldown = 3;
	void Start () {
		MusicSource = GetComponent<AudioSource>();
	}
	
	float nextSoundStartTime;
	void Update () {
		if(nextSoundStartTime < Time.time){
			playMusic();
		}
	}
	
	void playMusic(){
		MusicSource.clip = MusicClipList[Random.Range(0, MusicClipList.Count)];
		nextSoundStartTime = Time.time + Random.Range(minCooldown, maxCooldown) + MusicSource.clip.length;
		MusicSource.Play();
	}

}
