Help! Using 'isEmitting' bool to destroy object?

I’ve created a particle effect which I instantiate as a gameobject when the enemy dies. This works fine, but I don’t want the scene to get cluttered with these so I’d like to destroy them. I’ve tried to do a check to remove the object if the attached particle system is not emitting, but this doesn’t work and I’m not sure what I’m doing wrong.

I’ll paste the method below, please let me know if you need any more info. Any help would be greatly appreciated, thanks!

private void DeathExplosion()
    {
        GameObject deathExplosion = Instantiate(playerDeathParticle, transform.position, Quaternion.identity);
        ParticleSystem pm = deathExplosion.GetComponent<ParticleSystem>();
        if (pm.isEmitting == false)
        {
            Destroy(deathExplosion);
        }
    }

Privacy & Terms