using UnityEngine;
using System.Collections;

public class Bar : MonoBehaviour {

	public float barDisplay;
	public Vector2 pos = new Vector2(25,25);
	public Vector2 size = new Vector2(155,25);

	public Texture2D emptyTex;
	public Texture2D fullTex;

	public CharacterController player;

	public float checkPonit;
	public GameObject Play;
	public Globals globals;
	public Texture2D image;

	public float onCheckpiont = 0;



	// Use this for initialization
	void Start () {
		checkPonit = 0f;
		barDisplay = 1f;
		//player = GetComponent<CharacterController>();
	
	}

	void OnGUI(){

		if(onCheckpiont != 0){
			GUI.BeginGroup(new Rect(Screen.width/2 - size.x /2,pos.y,size.x,size.y));
			GUI.Box ( new Rect(0,0,size.x,size.y),"Checkpoint");

			GUI.EndGroup();

		}



		//Crosshair

		GUI.DrawTexture(new Rect(Screen.width / 2 - image.width/2, Screen.height / 2 - image.height/ 2, image.width/2, image.height/2), image);

		// BG
		GUI.BeginGroup(new Rect(pos.x,pos.y,size.x,size.y));
		GUI.Box ( new Rect(0,0,size.x,size.y),"Stamina");


		// Overlay

		GUI.BeginGroup(new Rect(0,0,size.x * barDisplay, size.y));
		GUI.Box(new Rect(0,0,size.x,size.y),"Stamina");

		GUI.EndGroup();
		GUI.EndGroup();





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

		if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0 || !player.isGrounded)
		{
			barDisplay = barDisplay - 0.03f * Time.deltaTime;
		}

		if(barDisplay <= 0)
		{
			Play.transform.position = globals.checkPoint;
			barDisplay = 1f;

		}





	
	}
}
