using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.SceneManagement;
using System.Collections;

public class Menu : MonoBehaviour
{
	public GameObject menu;
	public GameObject credits;

	private void Awake()
	{
		iTween.CameraFadeAdd();
		iTween.CameraFadeSwap(iTween.CameraTexture(Color.white));

		iTween.CameraFadeDepth(100);
		iTween.CameraFadeFrom(1, 1);
	}

	public void StartGameFade()
	{
		iTween.CameraFadeSwap(iTween.CameraTexture(Color.black));
		iTween.CameraFadeTo(iTween.Hash("amount", 1, "time", 9, "oncomplete", "StartGame", "oncompletetarget", gameObject));
	}

	private void Update()
	{
		if(Input.GetKey(KeyCode.Escape))
		{
			menu.SetActive(true);
			credits.SetActive(false);
		}
	}  

	private void StartGame()
	{
		SceneManager.LoadScene("Game");
		print("hoop!");
	}

	[Space(20)]

	public GameObject player;
	public Vector3 ascendAmount;
	public float ascendDelay;
	public float ascendTime;
	public iTween.EaseType easeAscend;

	public AudioClip ascendSound;
	public AudioClip loseSound;
	public AudioClip winSound;

	public AudioMixer mixer;

	[ContextMenu("TestEnd")]
	public void TestEnd()
	{
		AllCordeirosGot(6);
	}
	public void AllCordeirosGot(float delay)
	{
		print("Hoop");

		player.SetActive(true);

		if(winSound != null) AudioSource.PlayClipAtPoint(winSound, Camera.main.transform.position);

		if(ascendSound != null) AudioSource.PlayClipAtPoint(ascendSound, Camera.main.transform.position, 0.5f);
		player.GetComponentInChildren<Animator>().SetBool("Win", true);

		iTween.MoveAdd(player.gameObject, iTween.Hash("amount", ascendAmount, "time", ascendTime,
		"easetype", easeAscend, "delay", ascendDelay, "oncomplete", "AscendComplete"));

		player.BroadcastMessage("ArcoBegin");
	}
}