using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using Holoville.HOTween;

public class UnlockManager : MonoBehaviour {

	public GameObject player;
	public CanvasGroup canvas;
	public float unlockHeight = 95;
	public Behaviour[] unlocks;
	public string[] unlockMsg;
	public Text text;
	int wins = 0;
	bool hasWon = false;

	bool hidden = false;
	public AudioSource height;
	// Update is called once per frame
	void Update () {
		if(!hasWon && player.transform.position.y > unlockHeight){
			hasWon = true;
			if(unlocks.Length>wins){
				unlocks[wins].enabled = true;
				if(wins==0)text.text+="1              - default mode";
				text.text+="\n"+unlockMsg[wins];
				Show ();
			}
			wins++;
		}
		if(Input.GetKeyDown(KeyCode.R)){
			hasWon = false;
		}
		if(Input.GetKeyDown(KeyCode.H)){
			hidden = !hidden;
			if(hidden){
				Hide();
			}else{
				Show();
			}
		}
		height.volume = player.transform.position.y/unlockHeight*.8f;
	}
	
	void Hide(){
		HOTween.To(canvas,1,new TweenParms().Prop("alpha",0));
		Messenger.Broadcast("hide");
	}
	void Show(){
		HOTween.To(canvas,1,new TweenParms().Prop("alpha",1));
		Messenger.Broadcast("show");
	}

}
