using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class LevelTimer : MonoBehaviour {


    public GameObject TimeBar;
    public float TimeLeft = 980.0f;
    public float SetTime = 30.0f;
    private float TimeScale = 0.1f;
    //private Gui

	// Use this for initialization
	void Start () {

        TimeBar = GameObject.FindGameObjectWithTag("TimeBar");

        TimeScale = TimeLeft / SetTime;

	}
	
	// Update is called once per frame
	void Update () {

        //RectTransform curRect = 

        TimeLeft -= Time.deltaTime * TimeScale;
        if (TimeLeft < 0.0f)
        {
            TimeLeft = 0.0f;

            GameObject.FindGameObjectWithTag("GameOver").GetComponent<Text>().enabled = true;

            GameObject.FindGameObjectWithTag("CrystalControl").GetComponent<SequenceFlasher>().DeHilightCrystals();
            GameObject.FindGameObjectWithTag("CrystalControl").GetComponent<SequenceChecker>().enabled = false;
            GameObject.FindGameObjectWithTag("CrystalControl").GetComponent<MouseWait>().enabled = true;
            TimeLeft = 980.0f;
            this.enabled = false;

        }

        TimeBar.GetComponent<RectTransform>().sizeDelta = new Vector2(TimeLeft, 17); //Time.deltaTime * TimeScale, 0);
        /*
        float width = curRect.rect.width;
        width -= Time.deltaTime * TimeScale;

        if (width < 0.0f)
            width = 0.0f;

        RectTransform newRectTransform = new RectTransform(;
        newRectTransform.rect = curRect.rect;

        curRect.rect.width = width;

        TimeBar.GetComponent<RectTransform>().rect = curRect;*/

	}

    public void Reset()
    {
        TimeLeft = 980.0f;
        TimeBar.GetComponent<RectTransform>().sizeDelta = new Vector2(TimeLeft, 17); //Time.deltaTime * TimeScale, 0);
    
    }


    public void RemoveTime(float rem_time)
    {
        TimeLeft -= TimeScale * rem_time;


    } 
       

}
