34 lines
684 B
C#
34 lines
684 B
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class Health : MonoBehaviour
|
|
{
|
|
[Header ("Health")]
|
|
[SerializeField] private float startingHealth;
|
|
public float currentHealth { get; private set; }
|
|
|
|
private bool dead;
|
|
|
|
|
|
|
|
void Start()
|
|
{
|
|
currentHealth = startingHealth;
|
|
}
|
|
public void TakeDamage(float damage)
|
|
{
|
|
if (currentHealth > 0)
|
|
{
|
|
currentHealth -= damage;
|
|
Debug.Log($"{this.gameObject.name} was hit. Health: {currentHealth}");
|
|
}
|
|
else
|
|
{
|
|
Debug.Log($"{this.gameObject.name} is Dead");
|
|
dead = true;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
} |