Initial commit
This commit is contained in:
36
Assets/Scripts/Character.cs
Normal file
36
Assets/Scripts/Character.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user