Files
GoblinRaid/Assets/Scripts/Core/Health.cs

34 lines
707 B
C#
Raw Normal View History

2025-10-28 17:26:07 +00:00
using Unity.VisualScripting;
using UnityEngine;
2025-10-30 16:50:35 +00:00
namespace RPG.Core
2025-10-28 17:26:07 +00:00
{
public class Health : MonoBehaviour
{
[SerializeField] float health = 100f;
bool isDead = false;
public bool IsDead()
{
return isDead;
}
public void TakeDamage(float damage)
{
health = Mathf.Max(health - damage, 0);
if(health == 0)
{
Die();
}
}
private void Die()
{
if (isDead) return;
isDead = true;
GetComponent<Animator>().SetTrigger("die");
2025-10-30 16:50:35 +00:00
GetComponent<ActionScheduler>().CancelCurrentAction();
2025-10-28 17:26:07 +00:00
}
}
}