From 0ce0acae5e21971dab1a72d87f5d151b7bcc3058 Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sun, 17 Sep 2023 20:45:11 -0400 Subject: [PATCH] Fix MissingRefException when monster calls method OnDestroy Changes to Entity.cs to override Death method --- Assets/Scripts/Entity.cs | 2 +- Assets/Scripts/Opponent/Opponent.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index 5fc8a74..9886edf 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -35,7 +35,7 @@ public abstract class Entity : LevelObject Animation.SpeedMultiplier = SpeedMultiplier; } //Start the animation of death and the fading of the entity - public void Death() + public virtual void Death() { _animation.PlayDieAnim(); Invoke("Dying", 0.1f); diff --git a/Assets/Scripts/Opponent/Opponent.cs b/Assets/Scripts/Opponent/Opponent.cs index 6846178..a8ca40f 100644 --- a/Assets/Scripts/Opponent/Opponent.cs +++ b/Assets/Scripts/Opponent/Opponent.cs @@ -23,7 +23,7 @@ public class Opponent : Entity _rigidbody = GetComponent(); Animation = gameObject.AddComponent(); _observer = WaveObserver.Instance; - _toughness = Mathf.Round((base.Hp / 10) / 2); + _toughness = Mathf.Round((Hp / 10) / 2); _observerIndex = _observer.NotifyEnemy(transform.position.y, _toughness); } @@ -61,9 +61,10 @@ public class Opponent : Entity AttackSpeedWait += Time.deltaTime; } - private void OnDestroy() + public override void Death() { _observer.NotifyDies(_observerIndex, _toughness); + base.Death(); } }