You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RatAttack2D/Assets/Scripts/Health.cs

49 lines
1019 B

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;
}
}
}