diff --git a/Assets/Scripts/Effects/Explodable.cs b/Assets/Scripts/Effects/Explodable.cs index b2cfb84..a5c7dd7 100644 --- a/Assets/Scripts/Effects/Explodable.cs +++ b/Assets/Scripts/Effects/Explodable.cs @@ -6,9 +6,12 @@ namespace Saltosion.OneWeapon { public class Explodable : MonoBehaviour { public GameObject[] BodypartPrefabs; public bool DebugExplode = false; + [Tooltip("This only applies if this GameObject also has the Health component.")] + public bool KillOnZeroHealth = true; private CameraFX CameraFX; private PlayerFun PlayerFun; + private Health Health; private void Start() { foreach (GameObject Obj in BodypartPrefabs) { @@ -22,6 +25,7 @@ namespace Saltosion.OneWeapon { CameraFX = Camera.main.GetComponent(); PlayerFun = GameObject.FindGameObjectWithTag("Player").GetComponent(); + Health = GetComponent(); } private void Update() { @@ -29,6 +33,10 @@ namespace Saltosion.OneWeapon { DebugExplode = false; Explode(false); } + + if (Health != null && Health.CurrentHealth <= 0 && KillOnZeroHealth) { + Explode(true); + } } public void Explode(bool destroyGameObject) { diff --git a/Assets/Scripts/Enemies/Health.cs b/Assets/Scripts/Enemies/Health.cs index 27e1f03..74544b2 100644 --- a/Assets/Scripts/Enemies/Health.cs +++ b/Assets/Scripts/Enemies/Health.cs @@ -15,10 +15,7 @@ namespace Saltosion.OneWeapon { public void Damage(float amount, Vector2 fromDirection) { BloodLauncher.Splatter(transform.position, -fromDirection, (int)(amount), 100f, 100); - MaxHealth -= amount * (1 + PlayerFun.CurrentDamageBoost); - if (MaxHealth <= 0) { - MaxHealth = 0; - } + CurrentHealth -= amount * (1 + PlayerFun.CurrentDamageBoost); } } }