diff options
Diffstat (limited to 'GameCode/ReloadTigger.cs')
-rw-r--r-- | GameCode/ReloadTigger.cs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/GameCode/ReloadTigger.cs b/GameCode/ReloadTigger.cs new file mode 100644 index 0000000..3a4c093 --- /dev/null +++ b/GameCode/ReloadTigger.cs @@ -0,0 +1,40 @@ +using System; +using UnityEngine; +using UnityEngine.Events; + +public class ReloadTigger : MonoBehaviour +{ + public UnityEvent reloadDoneEvent; + + public UnityEvent outOfAmmoEvent; + + private void Start() + { + CharacterStatModifiers componentInParent = GetComponentInParent<CharacterStatModifiers>(); + componentInParent.OnReloadDoneAction = (Action<int>)Delegate.Combine(componentInParent.OnReloadDoneAction, new Action<int>(OnReloadDone)); + CharacterStatModifiers componentInParent2 = GetComponentInParent<CharacterStatModifiers>(); + componentInParent2.OutOfAmmpAction = (Action<int>)Delegate.Combine(componentInParent2.OutOfAmmpAction, new Action<int>(OnOutOfAmmo)); + } + + private void OnDestroy() + { + CharacterStatModifiers componentInParent = GetComponentInParent<CharacterStatModifiers>(); + componentInParent.OnReloadDoneAction = (Action<int>)Delegate.Remove(componentInParent.OnReloadDoneAction, new Action<int>(OnReloadDone)); + CharacterStatModifiers componentInParent2 = GetComponentInParent<CharacterStatModifiers>(); + componentInParent2.OutOfAmmpAction = (Action<int>)Delegate.Remove(componentInParent2.OutOfAmmpAction, new Action<int>(OnOutOfAmmo)); + } + + private void OnReloadDone(int bulletsReloaded) + { + reloadDoneEvent.Invoke(); + } + + private void OnOutOfAmmo(int bulletsReloaded) + { + outOfAmmoEvent.Invoke(); + } + + private void Update() + { + } +} |