private void Die() { Effect(); Destroy(gameObject); isAlive = false; // Calls the Explosion damage script to cause a damage on nearby gameobjects when this object dies. if (canExplode == true && explosionDamage != null) { explosionDamage.Explode(); } }
/// <summary> /// Trigger the explosion effect and automatically detach any spawned trail effects. /// </summary> public void Explode() { explosionDamage.Explode(); if (missile.isClusterBomb == true && missile.clusterBomb) { for (int i = 0; i <= missile.clusterBombNum; i++) { Instantiate(missile.clusterBomb, new Vector3(transform.position.x, transform.position.y + 1.5f, transform.position.z), transform.rotation); } } // If particle systems or trails are destroyed, their trail/particles do not persist. // Unparenting them before destruction prevents this. The missile calls this function // when it gets destroyed. DetachTrail(); if (explosionFXPrefab != null) { ParticleSystem explode = GameObject.Instantiate(explosionFXPrefab); explode.transform.position = transform.position; explode.transform.rotation = transform.rotation; // Give the explosion particle system the component to destroy itself after it finished playing. AARemoveEffect remove = explode.GetComponent <AARemoveEffect>(); if (remove == null) { remove = explode.gameObject.AddComponent <AARemoveEffect>(); } remove.readyToDestroy = true; } else { Debug.LogWarning("No ParticleSystem prefab assigned for explosions on missile " + transform.name + "."); } }