using UnityEngine;
using System.Collections;

[RequireComponent (typeof(AudioSource))]
public class MusicLoop : MonoBehaviour {
	public AudioClip introTrack;
	public AudioClip loopTrack;

	public AudioSource audioSource;

	void Start()
	{
		audioSource = gameObject.GetComponent<AudioSource> ();

		audioSource.clip = introTrack;
		audioSource.loop = false;
		audioSource.Play ();
	}

	void Update()
	{
		if (audioSource.clip == introTrack) {

			if (!audioSource.isPlaying)
			{
				audioSource.clip = loopTrack;
				audioSource.loop = true;
				audioSource.Play ();
			}
		}
	}
}
