Fix enemies not dying

This commit is contained in:
Jens Pitkänen 2019-08-07 21:13:54 +03:00
parent bdb0790629
commit a24880784a
2 changed files with 9 additions and 4 deletions

View File

@ -6,9 +6,12 @@ namespace Saltosion.OneWeapon {
public class Explodable : MonoBehaviour { public class Explodable : MonoBehaviour {
public GameObject[] BodypartPrefabs; public GameObject[] BodypartPrefabs;
public bool DebugExplode = false; public bool DebugExplode = false;
[Tooltip("This only applies if this GameObject also has the Health component.")]
public bool KillOnZeroHealth = true;
private CameraFX CameraFX; private CameraFX CameraFX;
private PlayerFun PlayerFun; private PlayerFun PlayerFun;
private Health Health;
private void Start() { private void Start() {
foreach (GameObject Obj in BodypartPrefabs) { foreach (GameObject Obj in BodypartPrefabs) {
@ -22,6 +25,7 @@ namespace Saltosion.OneWeapon {
CameraFX = Camera.main.GetComponent<CameraFX>(); CameraFX = Camera.main.GetComponent<CameraFX>();
PlayerFun = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerFun>(); PlayerFun = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerFun>();
Health = GetComponent<Health>();
} }
private void Update() { private void Update() {
@ -29,6 +33,10 @@ namespace Saltosion.OneWeapon {
DebugExplode = false; DebugExplode = false;
Explode(false); Explode(false);
} }
if (Health != null && Health.CurrentHealth <= 0 && KillOnZeroHealth) {
Explode(true);
}
} }
public void Explode(bool destroyGameObject) { public void Explode(bool destroyGameObject) {

View File

@ -15,10 +15,7 @@ namespace Saltosion.OneWeapon {
public void Damage(float amount, Vector2 fromDirection) { public void Damage(float amount, Vector2 fromDirection) {
BloodLauncher.Splatter(transform.position, -fromDirection, (int)(amount), 100f, 100); BloodLauncher.Splatter(transform.position, -fromDirection, (int)(amount), 100f, 100);
MaxHealth -= amount * (1 + PlayerFun.CurrentDamageBoost); CurrentHealth -= amount * (1 + PlayerFun.CurrentDamageBoost);
if (MaxHealth <= 0) {
MaxHealth = 0;
}
} }
} }
} }