using UnityEngine;
using System.Collections;

public class MinionJaugeScript : MonoBehaviour 
{

	public bool gameOver = false;
	public int actualhp = 150 ;
	public int maxhp = 200;
	public Vector3 barremaxhp;
	public Vector3 actualbarrehp;
	private Transform [] child;
	private Vector3 posbarre;
	public float testl;

	// Use this for initialization
	void Start () 
	{
		posbarre = this.transform.position;
		//actualhp = maxhp;
		//child = gameObject.GetComponentsInChildren<Transform> ();
		//child[1].localScale
		actualbarrehp = barremaxhp =this.gameObject.transform.localScale;
		refresh ();
	}

	/// <summary>
	/// utilisé pour baisser les PV  </summary>
	/// <param name="damageCount"></param>
	public void damage(int damageCount)
	{
		actualhp -= damageCount;
		if (actualhp <= 0)
		{
			gameOver = true;
			actualhp = 0;
			Debug.Log ("dead");

		}
		refresh();
	}

	/// <summary>
	/// utilisé pour augmenter les PV  </summary>
	/// <param name="healCount"></param>
	public void heal(int healCount)
	{
		actualhp += healCount;
		
		if (actualhp > maxhp)
		{

			actualhp = maxhp;
			
			Debug.Log("full life");
		}
		refresh ();
	}


	public void refresh()
	{
		//produit en croix 
		//
		//         maxhp    |  barremaxhp
		//         ______________________
		//         actualhp |  actualbarrehp
		actualbarrehp.y = actualhp * barremaxhp.y / maxhp; 
		this.gameObject.transform.localScale = actualbarrehp;
		Vector3 temp = posbarre;
		//temp.y -= actualhp*testl / maxhp ;
		this.gameObject.transform.position = temp;
	}


	void upadte(){
		refresh ();
	}


	//-3.27 0.83

//
//	 Position finale 0pv      positionact ?pv
//
//
//	testl					?



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