TigerProject/Assets/Scripts/Entity.cs

53 lines
1.0 KiB
C#
Raw Normal View History

2026-01-20 10:06:03 +00:00
using UnityEngine;
using UnityEngine.Events;
public class Entity : MonoBehaviour
{
2026-01-26 09:08:38 +00:00
[SerializeField] private int maxHp;
[SerializeField] private int attackDamage = 0;
2026-01-20 10:06:03 +00:00
[SerializeField] private EntityData data;
2026-01-26 09:08:38 +00:00
private int currentHp;
2026-01-20 10:06:03 +00:00
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;
2026-01-26 09:08:38 +00:00
2026-01-23 10:22:52 +00:00
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"))
{
2026-01-26 09:08:38 +00:00
if (attackDamage <= 0)
{
return;
}
2026-01-23 10:22:52 +00:00
other.gameObject.GetComponent<Player>().TakeDamage(attackDamage);
2026-01-26 09:08:38 +00:00
Destroy(this.gameObject);
2026-01-23 10:22:52 +00:00
}
}
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
}