From 2645aad5f41875b594635432ce9f75c314d24ee8 Mon Sep 17 00:00:00 2001 From: Maciekxdabu <40292375+Maciekxdabu@users.noreply.github.com> Date: Mon, 23 May 2022 12:48:43 +0200 Subject: [PATCH] merloj: added Soldier onDeath UnityEvent --- theProject/Assets/Scripts/Soldier.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/theProject/Assets/Scripts/Soldier.cs b/theProject/Assets/Scripts/Soldier.cs index d611ae63..dbeba977 100644 --- a/theProject/Assets/Scripts/Soldier.cs +++ b/theProject/Assets/Scripts/Soldier.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; +using UnityEngine.Events; public class Soldier : MonoBehaviour { @@ -43,10 +44,8 @@ public class Soldier : MonoBehaviour { Ally, Enemy - } - [SerializeField] private Soldier target; - [SerializeField] private SoldierType enemyType; - [SerializeField] private SoldierType ourType; + } + [Header("Values")] [SerializeField] private float maxHealthPoints = 10; [SerializeField] private float healthPoints = 1; [SerializeField] private float rangeAttack = 100; @@ -54,12 +53,20 @@ public class Soldier : MonoBehaviour [SerializeField] private float damageAttack = 1; [SerializeField] private int speedAttack = 1; // ticks between attacks [SerializeField] private int lastAttackTick = -1; - + [Header("References")] [SerializeField] private TMP_Text nameText = null; [SerializeField] private TMP_Text healthPointsText = null; + [Header("Do-not-change-in-game values")] + [SerializeField] private Soldier target; + [SerializeField] private SoldierType enemyType; + [SerializeField] private SoldierType ourType; [SerializeField] private Vector2Int movementDestination = Vector2Int.zero; + // variables not visible in inspector + + [HideInInspector] public UnityEvent onDeath = new UnityEvent(); + public SoldierType TempGetOwnType() { return ourType; @@ -109,6 +116,7 @@ public class Soldier : MonoBehaviour private void OnDestroy() { TickSystem.OnTick -= HandleTick; + onDeath.Invoke(); Debug.Log("Soldier: " + ourType.ToString() + " has died", gameObject); }