﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HealthBar : MonoBehaviour
{
  [SerializeField]
  private Stats playerStats;

  private Text healthText;
  private Slider healthBar;

  // Use this for initialization
  private void Start()
  {
    playerStats.GetComponent<HitDamage>().HasTakenDamage += OnDamage;
    healthBar = GetComponent<Slider>();
    healthText = GetComponentInChildren<Text>();

    OnDamage();
  }

  private void OnDamage()
  {
    healthBar.value = playerStats.health / playerStats.maxHealth;
    healthText.text = string.Format("{0}/{1}", playerStats.health, playerStats.maxHealth);
  }
}
