How would I make something happen only once when I press a key, and not happen again until I let go?

I’m trying to give my character the ability to jump. I’ve gotten it to apply force properly, but I can’t figure out how to make it only happen once when I press the key, and not happen again until I let go.

Could someone give some help?

The traditional way is to use GetButtonDown or GetKeyDown - these events are reported during only one Update cycle when the button/key is pressed. Furthermore, you should check the jump button/key only when the character is grounded, or the jump will happen even in mid-air when the jump control is pressed.

If you’re using a CharacterController, there’s a good example in 1 (do not use SimpleMove: it controls gravity and isn’t compatible with jumps).

Create a bool (for example “isJumping”), set it to true when the jump is initiated (and to false when the jump has finished), and check

if (!isJumping)

in your jump function.

Well we don’t know how your input works. If you posted your code the answer could be very easy to figure out.

but it’s very simple…
http://unity3d.com/support/documentation/ScriptReference/Input.html

look at that… should answer your question. for instance if using space bar to jump and you only want it to work while holding down the jump button you would use “GetKey” because it works as long as the key is being held down as opposed to GetKeyDown because that works only when the key is first pressed. It’s all in the link I referenced

Thanks for the help everyone, the Input.GetButtonDown is what worked best! Thank you!