mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-21 13:32:25 +01:00
cleaned up OnDestroy()
This commit is contained in:
parent
81cb9f5489
commit
a4f64abb66
@ -154,15 +154,19 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
mapSize: {x: 10, y: 10}
|
mapSize: {x: 10, y: 10}
|
||||||
WORLD_SPACE_OFFSET: {x: 0.5, y: 1, z: 0.5}
|
WORLD_SPACE_OFFSET: {x: 0.5, y: 1, z: 0.5}
|
||||||
|
allyBaseCoord: {x: 0, y: 0}
|
||||||
soldierStartingPositions:
|
soldierStartingPositions:
|
||||||
- {x: 0, y: 0}
|
- {x: 0, y: 0}
|
||||||
- {x: 1, y: 2}
|
- {x: 1, y: 2}
|
||||||
|
enemyBaseCoord: {x: 0, y: 0}
|
||||||
enemyStartingPositions:
|
enemyStartingPositions:
|
||||||
- {x: 2, y: 0}
|
- {x: 2, y: 0}
|
||||||
- {x: 9, y: 5}
|
- {x: 9, y: 5}
|
||||||
tilemap: {fileID: 1853262998}
|
tilemap: {fileID: 1853262998}
|
||||||
soldierPrefab: {fileID: 403095692180922766, guid: a87b1aa46b0ed3e0fba621e11dd4f1e2,
|
soldierPrefab: {fileID: 403095692180922766, guid: a87b1aa46b0ed3e0fba621e11dd4f1e2,
|
||||||
type: 3}
|
type: 3}
|
||||||
|
basePrefab: {fileID: 6141901885681798073, guid: e79038bbfa9535f45be1d0f0ae0626ce,
|
||||||
|
type: 3}
|
||||||
--- !u!4 &282616949
|
--- !u!4 &282616949
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@ -67,7 +67,7 @@ public class Soldier : MonoBehaviour
|
|||||||
|
|
||||||
// variables not visible in inspector
|
// variables not visible in inspector
|
||||||
|
|
||||||
[HideInInspector] public UnityEvent onDeath = new UnityEvent();
|
[HideInInspector] public UnityEvent<Soldier> onDeath = new UnityEvent<Soldier>();
|
||||||
|
|
||||||
public SoldierType GetOwnType()
|
public SoldierType GetOwnType()
|
||||||
{
|
{
|
||||||
@ -115,11 +115,15 @@ public class Soldier : MonoBehaviour
|
|||||||
TickSystem.OnTick += HandleTick;
|
TickSystem.OnTick += HandleTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Die()
|
||||||
|
{
|
||||||
|
TickSystem.OnTick -= HandleTick;
|
||||||
|
onDeath.Invoke(this);
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
TickSystem.OnTick -= HandleTick;
|
|
||||||
onDeath.Invoke();
|
|
||||||
|
|
||||||
Debug.Log("Soldier: " + ourType.ToString() + " has died", gameObject);
|
Debug.Log("Soldier: " + ourType.ToString() + " has died", gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +207,7 @@ public class Soldier : MonoBehaviour
|
|||||||
healthPoints -= damage;
|
healthPoints -= damage;
|
||||||
|
|
||||||
if (healthPoints <= 0)
|
if (healthPoints <= 0)
|
||||||
Destroy(gameObject);
|
Die();
|
||||||
|
|
||||||
UpdateHPDisplay();
|
UpdateHPDisplay();
|
||||||
Debug.Log("I took damage, oh my HP is now: " + healthPoints + " noooo!!!!", gameObject);
|
Debug.Log("I took damage, oh my HP is now: " + healthPoints + " noooo!!!!", gameObject);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user