TigerProject/Assets/Scripts/Monster/Entity.cs

54 lines
906 B
C#
Raw Normal View History

2026-01-20 10:06:03 +00:00
using UnityEngine;
using UnityEngine.Events;
public class Entity : MonoBehaviour
{
2026-01-27 12:06:26 +00:00
protected int maxHp;
protected int currentHp;
protected int attackDamage;
2026-01-20 10:06:03 +00:00
2026-01-27 12:06:26 +00:00
[SerializeField] protected EntityData data;
2026-01-20 10:06:03 +00:00
2026-01-27 12:06:26 +00:00
protected virtual void Awake()
2026-01-20 10:06:03 +00:00
{
2026-01-27 12:06:26 +00:00
if (data != null)
{
maxHp = data.maxHealth;
currentHp = data.maxHealth;
attackDamage = data.attackDamage;
}
2026-01-20 10:06:03 +00:00
}
2026-01-27 12:06:26 +00:00
public virtual void TakeDamage(int damage)
2026-01-20 10:06:03 +00:00
{
2026-01-27 12:06:26 +00:00
currentHp -= damage;
2026-01-23 10:22:52 +00:00
if (currentHp <= 0)
2026-01-20 10:06:03 +00:00
{
2026-01-27 12:06:26 +00:00
Die();
2026-01-20 10:06:03 +00:00
}
}
2026-01-27 12:06:26 +00:00
protected virtual void Die()
2026-01-23 10:22:52 +00:00
{
2026-01-27 12:06:26 +00:00
currentHp = 0;
Destroy(gameObject);
2026-01-23 10:22:52 +00:00
}
2026-01-27 12:06:26 +00:00
public virtual void OnHitPlayer(Player player)
2026-01-20 10:06:03 +00:00
{
2026-01-27 12:06:26 +00:00
player.TakeDamage(attackDamage);
Die();
}
public virtual void RunAI()
{
2026-01-20 10:06:03 +00:00
}
2026-01-27 12:06:26 +00:00
void Update()
2026-01-20 10:06:03 +00:00
{
2026-01-27 12:06:26 +00:00
RunAI();
2026-01-20 10:06:03 +00:00
}
2026-01-23 10:22:52 +00:00
}