How To Enable/Disable And Disable Particles Upon Button Input

Hi guys,
I have a spaceship that has particles attached to it that resemble thrusters on a real spacecraft. I also have a C# script that controls the ship motion (You know, forward, backward/Up arrow, back arrow). I want to be able to have the particles off and then when I press any of the arrow keys, I want the particles to come on and emit so that It will come on when I press any arrow keys and go off when I am not pressing any. I also don’t want them [particles] to just turn off. I want them to slowly turn off. Thanks for any code you can provide. I will try to be most helpful. Thank you in advance.

To turn the particles on or off you can change the emission rate from 0 to your default value. This will cause them to stop emitting new particles but will let the old ones die off, so emulate the engine turning off. If you want you can even decrease them over time to emulate the engine slowly shutting down.

This code could work if the particle system is a component of the object you attach the script to:

if (Input.GetAxis("Vertical") == 0 ) {
    particleSystem.emissionRate = 0;
} else {
    particleSystem.emissionRate = engineOnEmissionRate;
}

If not, you’ll have to first get the GameObject to which the ParticleSystem is attached:

GameObject particleSystemGameObj = GameObject.FindGameObjectWithTag("ParticleSystem");
particlseSystemGameObj.particleSystem.emissionRate = 0;

Make sure to tag the game object that contains the particle system with the “ParticleSystem” tag (or any tag you decide to use) for the second option to work.

Good luck!