/// <summary> /// Trigger the explosion effect and automatically detach any spawned trail effects. /// </summary> public void Explode() { // 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 + "."); } }
private void Start() { // First make sure that an effect was assigned at all. if (trailPrefab != null || particleTrailPrefab != null) { // Make sure there is a reference point for where to spawn the trail. if (trailFxPoint == null) { // There isn't an already assigned one. Check to see if one already exists. trailFxPoint = transform.Find("TrailFx"); // Still haven't found one, just make a new one. if (trailFxPoint == null) { trailFxPoint = transform; Debug.Log("No trail effect point given, or child object named \"TrailFx\" to place the missile trail effect on " + name + ". Using object origin instead."); } } // Instantiate the TrailRenderer trail. if (trailPrefab != null) { trail = Instantiate(trailPrefab, trailFxPoint); trail.transform.localPosition = Vector3.zero; trail.transform.localEulerAngles = Vector3.zero; trail.enabled = false; } // Instantiate the ParticleSystem trail. if (particleTrailPrefab != null) { particleTrail = Instantiate(particleTrailPrefab, trailFxPoint); particleTrail.transform.localPosition = Vector3.zero; particleTrail.transform.localEulerAngles = Vector3.zero; particleTrail.Stop(); // Ensure that the effect remover is on the gameobject to prevent undeleted particle effects. if (particleTrail.GetComponent <AARemoveEffect>() == null) { effectRemover = particleTrail.gameObject.AddComponent <AARemoveEffect>(); } } } }