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

[RequireComponent(typeof(CharacterData))]
public class HealthbarUI : MonoBehaviour {

    private CharacterData _myCharacterData;
    public Image HealthBarImage;

	// Use this for initialization
	void Start () {
	
        _myCharacterData = GetComponent<CharacterData>();

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

        var hitpointPercentage = _myCharacterData.HitPoints / 100.0f;

        Mathf.Clamp(hitpointPercentage, 0.0f, 100.0f);

        HealthBarImage.rectTransform.transform.localScale = new Vector3(hitpointPercentage, 1.0f, 1.0f);
	}
}
