47 lines
917 B
C#
47 lines
917 B
C#
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class Entity : MonoBehaviour
|
|
{
|
|
private int maxHp;
|
|
private int currentHp;
|
|
private int attackDamage;
|
|
|
|
[SerializeField] private EntityData data;
|
|
|
|
void Awake()
|
|
{
|
|
maxHp = data.maxHealth;
|
|
currentHp = data.maxHealth;
|
|
attackDamage = data.attackDamage;
|
|
}
|
|
|
|
public virtual void TakeDamage(int playerAttackDamage)
|
|
{
|
|
currentHp -= playerAttackDamage;
|
|
if (currentHp <= 0)
|
|
{
|
|
currentHp = 0;
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
if (other.CompareTag("Player"))
|
|
{
|
|
other.gameObject.GetComponent<Player>().TakeDamage(attackDamage);
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
this.RunAI();
|
|
}
|
|
|
|
public virtual void RunAI()
|
|
{
|
|
|
|
}
|
|
} |