From b83e516940e501de099bcc2337d958663149fd32 Mon Sep 17 00:00:00 2001 From: Jens Pitkanen Date: Sun, 18 Aug 2019 22:27:37 +0300 Subject: [PATCH] Fix enemies exploding more than once and misc --- Assets/Prefabs/Bullets/ShotgunBullet.prefab | 4 ++-- Assets/Prefabs/Bullets/ShotgunSubBullet.prefab | 2 +- Assets/Scripts/Effects/Explodable.cs | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Assets/Prefabs/Bullets/ShotgunBullet.prefab b/Assets/Prefabs/Bullets/ShotgunBullet.prefab index 0248e27..7d55df6 100644 --- a/Assets/Prefabs/Bullets/ShotgunBullet.prefab +++ b/Assets/Prefabs/Bullets/ShotgunBullet.prefab @@ -26,7 +26,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6729850174041497321} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -19.990198, y: 7.5981717, z: -12.029297} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -61,5 +61,5 @@ MonoBehaviour: m_EditorClassIdentifier: SubBullet: {fileID: 4482402865533696887, guid: 6895e4efeafdc3a4f8f4296856a389fc, type: 3} - BulletsShot: 5 + BulletsShot: 8 TotalArc: 90 diff --git a/Assets/Prefabs/Bullets/ShotgunSubBullet.prefab b/Assets/Prefabs/Bullets/ShotgunSubBullet.prefab index 11287b6..d9a18f9 100644 --- a/Assets/Prefabs/Bullets/ShotgunSubBullet.prefab +++ b/Assets/Prefabs/Bullets/ShotgunSubBullet.prefab @@ -9611,7 +9611,7 @@ MonoBehaviour: Sprite: {fileID: 5552990435088311320} Trail: {fileID: 4595570391660610945} Explosion: {fileID: 6411602551704027216} - Damage: 3.7 + Damage: 2.5 --- !u!1 &5552990435088311320 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Effects/Explodable.cs b/Assets/Scripts/Effects/Explodable.cs index c37ef22..13ddce6 100644 --- a/Assets/Scripts/Effects/Explodable.cs +++ b/Assets/Scripts/Effects/Explodable.cs @@ -14,6 +14,8 @@ namespace Saltosion.OneWeapon.Effects { private CameraFX CameraFX; private PlayerFun PlayerFun; + private bool DestroyedAlready = false; + private void Start() { foreach (GameObject Obj in BodypartPrefabs) { Rigidbody2D Body = Obj.GetComponent(); @@ -36,6 +38,16 @@ namespace Saltosion.OneWeapon.Effects { } public void Explode(bool destroyGameObject) { + if (destroyGameObject) { + // Destroying the object during explosion implies that it can explode only once, + // but Destroy() doesn't happen instantly, so here's a guard for that. + if (DestroyedAlready) { + return; + } else { + DestroyedAlready = true; + } + } + int Count = (int)(BodypartMinCount + (BodypartMaxCount - BodypartMinCount) * Random.value); for (int i = 0; i < Count; i++) { GameObject Obj = BodypartPrefabs[i % BodypartPrefabs.Length];