37 lines
773 B
C#
37 lines
773 B
C#
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.AI;
|
|
|
|
public abstract class Character : MonoBehaviour
|
|
{
|
|
[Header("Stats")]
|
|
public int CurHp = 10;
|
|
public int MaxHp = 10;
|
|
|
|
[Header("Components")]
|
|
// Optional movement controller reference, assign in inspector if used
|
|
public NavMeshMovementController MovementController;
|
|
|
|
protected Character target;
|
|
public event UnityAction onTakeDamage;
|
|
|
|
public void TakeDamage(int damageToTake)
|
|
{
|
|
CurHp -= damageToTake;
|
|
onTakeDamage?.Invoke();
|
|
if (CurHp <= 0) Die();
|
|
}
|
|
|
|
public virtual void Die()
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public void SetTarget(Character t)
|
|
{
|
|
target = t;
|
|
}
|
|
|
|
public Character GetTarget() => target;
|
|
}
|