Fix MissingRefException when monster calls method OnDestroy

Changes to Entity.cs to override Death method
This commit is contained in:
Ader Alisma 01 2023-09-17 20:45:11 -04:00
parent def7c9f30d
commit 0ce0acae5e
2 changed files with 4 additions and 3 deletions

View File

@ -35,7 +35,7 @@ public abstract class Entity : LevelObject
Animation.SpeedMultiplier = SpeedMultiplier; Animation.SpeedMultiplier = SpeedMultiplier;
} }
//Start the animation of death and the fading of the entity //Start the animation of death and the fading of the entity
public void Death() public virtual void Death()
{ {
_animation.PlayDieAnim(); _animation.PlayDieAnim();
Invoke("Dying", 0.1f); Invoke("Dying", 0.1f);

View File

@ -23,7 +23,7 @@ public class Opponent : Entity
_rigidbody = GetComponent<Rigidbody2D>(); _rigidbody = GetComponent<Rigidbody2D>();
Animation = gameObject.AddComponent<AnimationEntity>(); Animation = gameObject.AddComponent<AnimationEntity>();
_observer = WaveObserver.Instance; _observer = WaveObserver.Instance;
_toughness = Mathf.Round((base.Hp / 10) / 2); _toughness = Mathf.Round((Hp / 10) / 2);
_observerIndex = _observer.NotifyEnemy(transform.position.y, _toughness); _observerIndex = _observer.NotifyEnemy(transform.position.y, _toughness);
} }
@ -61,9 +61,10 @@ public class Opponent : Entity
AttackSpeedWait += Time.deltaTime; AttackSpeedWait += Time.deltaTime;
} }
private void OnDestroy() public override void Death()
{ {
_observer.NotifyDies(_observerIndex, _toughness); _observer.NotifyDies(_observerIndex, _toughness);
base.Death();
} }
} }