using UnityEngine;
using System.Collections;

public class HUD : MonoBehaviour {
	public Rect healthPosition;
	public Rect ammoPostiion;
	
	public GUISkin skin;
	public Texture2D healthImage;
	public Texture2D armorImage;
	public Texture2D ammoImage;
	public Texture2D blood;
	
	private float bloodTime;
	public float bloodTimeMax;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		bloodTime-=Time.deltaTime;
		if(bloodTime<0)
			bloodTime=0;
	}
	
	
	void OnGUI()
	{
		GUI.skin = skin;
		
		
		
		
		float xSizePercent = Screen.width / 1680.0f;
		float ySizePercent = Screen.height / 1050.0f;	
		
		//Health
		Rect rect = new Rect(healthPosition.x * xSizePercent,healthPosition.y * ySizePercent,healthPosition.width,healthPosition.height);
		
		string hp = transform.GetComponent<UnitStatus>().health.ToString();
		GUI.DrawTexture(rect,healthImage); rect.x+=60; rect.y+=8;
		if(transform.GetComponent<UnitStatus>().health>30){GUI.color=Color.white;}else{GUI.color=Color.red;}
		GUI.Label(rect,"Health: "+hp); rect.x-=60; rect.y-=8;
		GUI.color = Color.white;
		rect.y+=GUI.skin.label.CalcSize(new GUIContent(hp)).y*1.25f;
		string armor =transform.GetComponent<UnitStatus>().armor.ToString();
		GUI.DrawTexture(rect,armorImage); rect.x+=60; rect.y+=8;
		GUI.Label(rect,"Armor: "+armor);rect.x-=60; rect.y-=8;
		rect = new Rect(Screen.width - ammoPostiion.width,ammoPostiion.y*ySizePercent,ammoPostiion.width,ammoPostiion.height);
		string ammo = transform.GetComponent<PlayerControll>().GetAmmo().ToString();
		GUI.DrawTexture(rect,ammoImage); rect.x+=60; rect.y+=8;
		GUI.Label(rect,"Ammo: "+ammo);rect.x-=60; rect.y-=8;
		
		
		rect.y+=GUI.skin.label.CalcSize(new GUIContent(ammo)).y*1.5f;
		string weapon = GameObject.FindGameObjectWithTag("Game").GetComponent<GunController>().guns[transform.GetComponent<PlayerControll>().selectedWeapon].name;
		GUI.Label(rect,weapon);
		
		GUI.color = new Color(1,1,1,0.2f*(bloodTime/bloodTimeMax));
		GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),blood);

	}
	

	public void Auch()
	{
		bloodTime=bloodTimeMax;	
	}
}
