cleaned up OnDestroy()

This commit is contained in:
Gabriel Ksawery Skowron-Rodriguez 2022-05-23 13:20:08 +02:00
parent 81cb9f5489
commit a4f64abb66
2 changed files with 13 additions and 5 deletions

View File

@ -154,15 +154,19 @@ MonoBehaviour:
m_EditorClassIdentifier:
mapSize: {x: 10, y: 10}
WORLD_SPACE_OFFSET: {x: 0.5, y: 1, z: 0.5}
allyBaseCoord: {x: 0, y: 0}
soldierStartingPositions:
- {x: 0, y: 0}
- {x: 1, y: 2}
enemyBaseCoord: {x: 0, y: 0}
enemyStartingPositions:
- {x: 2, y: 0}
- {x: 9, y: 5}
tilemap: {fileID: 1853262998}
soldierPrefab: {fileID: 403095692180922766, guid: a87b1aa46b0ed3e0fba621e11dd4f1e2,
type: 3}
basePrefab: {fileID: 6141901885681798073, guid: e79038bbfa9535f45be1d0f0ae0626ce,
type: 3}
--- !u!4 &282616949
Transform:
m_ObjectHideFlags: 0

View File

@ -67,7 +67,7 @@ public class Soldier : MonoBehaviour
// variables not visible in inspector
[HideInInspector] public UnityEvent onDeath = new UnityEvent();
[HideInInspector] public UnityEvent<Soldier> onDeath = new UnityEvent<Soldier>();
public SoldierType GetOwnType()
{
@ -115,11 +115,15 @@ public class Soldier : MonoBehaviour
TickSystem.OnTick += HandleTick;
}
private void Die()
{
TickSystem.OnTick -= HandleTick;
onDeath.Invoke(this);
Destroy(gameObject);
}
private void OnDestroy()
{
TickSystem.OnTick -= HandleTick;
onDeath.Invoke();
Debug.Log("Soldier: " + ourType.ToString() + " has died", gameObject);
}
@ -203,7 +207,7 @@ public class Soldier : MonoBehaviour
healthPoints -= damage;
if (healthPoints <= 0)
Destroy(gameObject);
Die();
UpdateHPDisplay();
Debug.Log("I took damage, oh my HP is now: " + healthPoints + " noooo!!!!", gameObject);