using UnityEngine;
using System.Collections.Generic;

public class PlayerHUD: MonoBehaviour {

	public Rect healthBackPos, healthFrontPos, healthtxtPos;
	
	public Texture2D health;
	public Texture2D back;
	
	private PlayerState pState;
	
	// Use this for initialization
	void Start () {
		
		int h = Screen.height;
		//int w = Screen.width;
		
		healthtxtPos = new Rect(30, h-150, 100, 30);
		healthFrontPos = new Rect(110,h-150,100,30);
		healthBackPos = new Rect(110,h-150,100,30);
		
		GameObject gamePlayer = GameObject.FindWithTag("Player1");
		if(gamePlayer != null)
			pState = gamePlayer.GetComponent<PlayerState>();
		else 
			pState = null;
	}
	
	// Update is called once per frame
	void OnGUI () 
	{
		if(pState == null) return;
		
		healthFrontPos.width = (int)(pState.Health);
		
		GUI.Label(healthtxtPos, "Health");
		GUI.DrawTexture(healthBackPos,back);
		GUI.DrawTexture(healthFrontPos,health);
	}
}
