I’ve created a GameObject (renamed “Explosion”) with three childs. Every child has a different Particle System (Smoke, Sphere and Ring) to create an explosion effect and I want auto-destroy the parent GameObject “Explosion” and all childs once all Particle Systems finished playing.
To do this I’ve created this script “ManagerExplosion”
public ParticleSystem smoke;
public ParticleSystem sphere;
public ParticleSystem ring;
// Use this for initialization
void Start () {
smoke = GetComponent<ParticleSystem>();
sphere = GetComponent<ParticleSystem>();
ring = GetComponent<ParticleSystem>();
}
// Update is called once per frame
void Update () {
if (!smoke.IsAlive() && !sphere.IsAlive() && !ring.IsAlive())
{
Destroy(gameObject);
}
Using another script, I create the instance
public GameObject explosion;
void Start () {
Instantiate(explosion);
}
This is the GameObject “Explosion” and the script with the three Particle System that I’ve dragged
The issue is when I launch the game it Instantiate prefab correctly and all Particle Systems works but, as you can see, I lose all references Perticle Systems and the GameObject “Explosion” is not destroyed…
Obviously I get an error because there is not attached Particle System:
MissingComponentException: There is no ‘ParticleSystem’ attached to the “Explosion(Clone)” game object, but a script is trying to access it.
So, what am I doing wrong?