using UnityEngine;
using System.Collections;

public class TemaFade : MonoBehaviour {

	public AudioClip temaShort;
	public AudioClip temaLong;
	private AudioSource audioSource;
	private bool lowerVolume = false;
	private bool raiseVolume = false;

	// Use this for initialization
	void Start () {
		audioSource = GetComponent<AudioSource> ();
	}
	
	// Update is called once per frame
	void Update () {
		if (lowerVolume) {
			audioSource.volume -= 1 * Time.deltaTime;
			if (audioSource.volume == 0) lowerVolume = false;
		}

		if (raiseVolume) {
			audioSource.volume += 1* Time.deltaTime;
			if (audioSource.volume == 1) raiseVolume = false;
		}
	}

	public void SwitchSoundClip() {
		StartCoroutine (Fade());
	}

	private IEnumerator Fade() {
		lowerVolume = true;
		yield return new WaitForSeconds(2f);
		audioSource.clip = temaLong;
		audioSource.loop = true;
		audioSource.Play();
		raiseVolume = true;

	}
}
