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

public class Health : MonoBehaviour
{
    public int PreHP;
    public int MaxHP {get; private set;}
    public int Hp  {get; private set;}
    private void Start()
    {
        MaxHP = PreHP;
        Hp = MaxHP;
    }
    public void RemoveHP(int Damage)
    {
        Hp -= Damage;
        hpCheck();
    }
    public void AddHP(int In)
    {
        Hp += In;
        hpCheck();
    }
    public void AddMax(int hp)
    {

    }
    private void hpCheck()
    {
        if(Hp <=0)
        {
            if(gameObject.CompareTag("Enemy"))
            {
                GameObject.Destroy(gameObject);
            }
            if(gameObject.CompareTag("Player"))
            {
                GameObject.Find("Canvas").GetComponent<GameOverScreen>().Setup(0);
                GameObject.Find("Canvas").GetComponent<HeartScript>().die();
            }
        }
        if(Hp > MaxHP)
        {
            Hp = MaxHP;
        }
    }
}
