Fix enemies exploding more than once and misc

This commit is contained in:
Jens Pitkänen 2019-08-18 22:27:37 +03:00
parent 4e2449aa68
commit b83e516940
3 changed files with 15 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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<Rigidbody2D>();
@ -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];