- Home /
turn on off particle system
Hello 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.
Any help is appreciated Thanking You
Hey Allan,
Its a while ago but did you get your water gun to work i.e. stop emitting when releasing the key?
Because I'm having the exact same issue and my code looks a lot like yours although I'm using a particle emitter and not a particle system. When i press and hold the key I defined it works great but when I release the key the emitter doesn't disappear. it just freezes.
Hope you got yours to work and can help me too heres my code:
public class ParticleEmitter1: $$anonymous$$onoBehaviour { public ParticleEmitter smallflames2; void Update () { if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.UpArrow)){ smallflames2.particleEmitter.enabled = true; }else if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.UpArrow)){ smallflames2.particleEmitter.enabled = false;; } } }
Answer by Auggie · Mar 14, 2013 at 02:43 AM
i am fairly new in Unity but i think this is the code you're looking for:
public ParticleSystem waterGun;
void Update () {
if(Input.GetKey(KeyCode.W)){
waterGun.emit = true;
}else if(Input.GetKeyUp(KeyCode.W)){
waterGun.emit = false;
}
}
Your answer
Follow this Question
Related Questions
How to draw an arrow from fps contoller 1 Answer
Mathf.pingpong 4 Answers
FPS Controller rotate between two points c# 2 Answers
Hide the ImageTraget in Real world 0 Answers
how to get in game numerical input 1 Answer