TigerProject/Assets/Scripts/Entity.cs

47 lines
917 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-23 10:22:52 +00:00
private int maxHp;
private int currentHp;
private int attackDamage;
2026-01-20 10:06:03 +00:00
[SerializeField] private EntityData data;
void Awake()
{
2026-01-23 10:22:52 +00:00
maxHp = data.maxHealth;
currentHp = data.maxHealth;
2026-01-20 10:06:03 +00:00
attackDamage = data.attackDamage;
}
public virtual void TakeDamage(int playerAttackDamage)
2026-01-20 10:06:03 +00:00
{
2026-01-23 10:22:52 +00:00
currentHp -= playerAttackDamage;
if (currentHp <= 0)
2026-01-20 10:06:03 +00:00
{
2026-01-23 10:22:52 +00:00
currentHp = 0;
Destroy(gameObject);
2026-01-20 10:06:03 +00:00
}
}
2026-01-23 10:22:52 +00:00
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
other.gameObject.GetComponent<Player>().TakeDamage(attackDamage);
Destroy(gameObject);
}
}
void Update()
2026-01-20 10:06:03 +00:00
{
2026-01-23 10:22:52 +00:00
this.RunAI();
2026-01-20 10:06:03 +00:00
}
2026-01-23 10:22:52 +00:00
public virtual void RunAI()
2026-01-20 10:06:03 +00:00
{
2026-01-23 10:22:52 +00:00
2026-01-20 10:06:03 +00:00
}
2026-01-23 10:22:52 +00:00
}