unity3d turn on off particle system

Alan Fletcher picture Alan Fletcher · Mar 13, 2013 · Viewed 16.9k times · Source

i am trying to turn on and off a particle system i created.
I attached it to a prefab.

The code I am using is as follows

public ParticleSystem waterGun;

void Update () {
    if(Input.GetKey(KeyCode.W)){
        waterGun.enableEmission = true;
    }else if(Input.GetKeyUp(KeyCode.W)){
        waterGun.enableEmission = false;
    }
}

I want the particle system to play in front of the fps when a key is held down and stop playing when it is pressed.

Answer

Corne picture Corne · Apr 22, 2013

Try using:

waterGun.Play();

and

waterGun.Stop();

And also, your logic is inverted, like Joetjah said.