sort of fix

This commit is contained in:
Gabriel Ksawery Skowron-Rodriguez 2022-05-23 14:15:06 +02:00
parent 42452e6e64
commit 28f7e76c0b
2 changed files with 19 additions and 18 deletions

View File

@ -21,7 +21,6 @@ public class Entity : MonoBehaviour
[HideInInspector] public UnityEvent<Entity> OnDeath = new UnityEvent<Entity>(); [HideInInspector] public UnityEvent<Entity> OnDeath = new UnityEvent<Entity>();
public Team GetOwnTeam() public Team GetOwnTeam()
{ {
return myTeam; return myTeam;
@ -51,6 +50,18 @@ public class Entity : MonoBehaviour
} }
} }
protected virtual void Awake()
{
TickSystem.OnTick += HandleTick;
}
protected virtual void Die()
{
TickSystem.OnTick -= HandleTick;
OnDeath.Invoke(this);
Destroy(gameObject);
}
public void SetOwnTeam(Team type) public void SetOwnTeam(Team type)
{ {
myTeam = type; myTeam = type;
@ -61,17 +72,16 @@ public class Entity : MonoBehaviour
healthPoints -= damage; healthPoints -= damage;
if (healthPoints <= 0) if (healthPoints <= 0)
Destroy(gameObject); Die();
UpdateHPDisplay(); UpdateHPDisplay();
Debug.Log("I took damage, my HP is now: " + healthPoints + " noooo!!!!", gameObject); Debug.Log("I took damage, my HP is now: " + healthPoints + " noooo!!!!", gameObject);
} }
protected virtual void Die() protected virtual void HandleTick(TickSystem.OnTickEventArgs tickEventArgs)
{ {
OnDeath.Invoke(this);
Destroy(gameObject); }
}
private void OnDestroy() private void OnDestroy()
{ {

View File

@ -66,19 +66,10 @@ public class Soldier : Entity
else enemyType = Team.Ally; else enemyType = Team.Ally;
} }
void Awake() protected override void HandleTick(TickSystem.OnTickEventArgs tickEventArgs)
{
TickSystem.OnTick += HandleTick;
}
protected override void Die()
{ {
TickSystem.OnTick -= HandleTick; // base.HandleTick(tickEventArgs);
base.Die();
}
private void HandleTick(TickSystem.OnTickEventArgs tickEventArgs)
{
ref Queue<Action> queueToHandle = ref interrupts; ref Queue<Action> queueToHandle = ref interrupts;
if (interrupts.Count < 1) // if no interrupt actions to do, handle regular queue if (interrupts.Count < 1) // if no interrupt actions to do, handle regular queue
queueToHandle = actions; queueToHandle = actions;