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

34 lines
704 B
C#
Raw Permalink 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);
2025-10-31 20:33:41 +00:00
if (health == 0)
2025-10-28 17:26:07 +00:00
{
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
}
2025-10-31 20:33:41 +00:00
}
2025-10-28 17:26:07 +00:00
}