Files
dungeons/Assets/Scripts/Components/HealthComponent.cs

42 lines
684 B
C#

using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class HealthComponent : MonoBehaviour
{
[ReadOnly]
[SerializeField]
private int health;
public UnityEvent onDied;
public void Setup(int health)
{
this.health = health;
}
public void TakeDamage(int damage)
{
health -= damage;
if (health < 0)
{
health = 0;
}
if (health == 0)
{
onDied.Invoke();
}
}
[Button]
private void Kill()
{
TakeDamage(health);
}
}