- Home /
Jetpack flame only in the air
So far I have a script working that activated my flame particle emmiter with a keypress of space
Blockquote
Blockquote> private var pe : ParticleEmitter;
function Start() { pe = GetComponent(ParticleEmitter); }
function Update() { if (Input.GetKeyDown("space")) pe.emit = !pe.emit;
}Blockquote
Blockquote
what i want is when I land it turns it off, meaning the flame would activate upon keypress of space which also makes my character jump, and then turns off when he lands. Any ideas? Thanks
i was wondering if youcould right the code like the guy below so that i could understand it better
also how do you make it so that when you press and hold down a key (exg. hold down space) you get the particle effect to turn on but it turns off as soon as you let go?
Answer by Joshua · Feb 21, 2011 at 09:27 PM
Assuming your character/player has a character controller,
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {if (controller.isGrounded) {}
Makes him execute commands only when on the ground.
So a way you could do it is make a static var petoggle = true; and then in the if controller is grounded part of your script turn it to false, and then in your particle emiters script put an if(petoggle) { the press space to fire stuff} else { the not emit stuff}
Hope this works. I'm a new to unity myself though so it may be that what I say is utter nonsense. :p
the if (controller.grounded) part and the petoggle stuff must be put in the script that controls your character of course. :)
Hmnn I get this error
$$anonymous$$ identifier: 'controller'.
I forgot to define controller -.- sorry for wasting your time.
Your answer
![](https://koobas.hobune.stream/wayback/20220613105548im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Having trouble turning off gravity through script 1 Answer
Turn on/off Script 3 Answers
Turn off another script with Javascript 1 Answer
JetPackParticleController not working in the 3D Platformet Tutorial 0 Answers
Light script flashes on and off 1 Answer