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

public class Healthbar : MonoBehaviour
{
    public Health health;
    public Slider slider;
    public Sprite lowFace;
    public Sprite veryLowFace;
    public Image face;
    void Start()
    {
        slider.maxValue = health.maxHealth;
        slider.value = slider.maxValue;
        health.hit.AddListener(UpdateBar);
    }
    
    private void UpdateBar(){
        slider.value = health.GetCurrentHealth();
        switch(slider.value){
            case 3:
                face.sprite = lowFace;
                break;
            case 1:
                face.sprite = veryLowFace;
                break;
        }
    }
}
