TigerProject/Assets/Scripts/Entity.cs

44 lines
760 B
C#
Raw Normal View History

2026-01-20 10:06:03 +00:00
using UnityEngine;
using UnityEngine.Events;
public class Entity : MonoBehaviour
{
private int maxHealth;
private int currentHealth;
private int attackDamage;
2026-01-20 10:06:03 +00:00
[SerializeField] private EntityData data;
void Awake()
{
maxHealth = data.maxHealth;
currentHealth = data.maxHealth;
attackDamage = data.attackDamage;
}
public virtual void TakeDamage(int playerAttackDamage)
2026-01-20 10:06:03 +00:00
{
currentHealth -= playerAttackDamage;
2026-01-20 10:06:03 +00:00
if (currentHealth <= 0)
{
currentHealth = 0;
Destroy(gameObject);
2026-01-20 10:06:03 +00:00
}
}
void Update()
2026-01-20 10:06:03 +00:00
{
RunAI();
2026-01-20 10:06:03 +00:00
}
protected void RunAI() { }
public int getAttackDamage()
2026-01-20 10:06:03 +00:00
{
return attackDamage;
2026-01-20 10:06:03 +00:00
}
2026-01-20 10:06:03 +00:00
}