- Home /
 
Jump character with click on space key in Javascript
Hi. I created a simple game in Unity with JavaScript and I want when Space key is pressed, character jump, I did a lot of Search about jump function, but I was not successful to find its code! I have completely confused. What code to write? Thanks.
Answer by ShawnFeatherly · Jul 27, 2016 at 04:21 PM
By default the space bar is tied to the "Jump" key. There are 3 kinds of "Jump" events.
When space bar first goes down from being pressed:
Input.GetButtonDown("Jump")When space bar gets released:
Input.GetButtonUp("Jump")Every frame the space bar is held down:
Input.GetButton("Jump")
Here's a video with details of how to use Input.GetButton: https://unity3d.com/learn/tutorials/topics/scripting/getbutton-and-getkey
Here's a basic implementation.
 function Update ()
 {        
   if (Input.GetButtonDown("Jump"))
   {
     // code that moves your character in a jump like manner
   }
 }
 
              Your answer
 
             Follow this Question
Related Questions
Mecanim jump animation 0 Answers
How can I limit jump height in unity? 3 Answers
2D Horizontal trampoline/spirng issues 1 Answer
Why the ball is not jumping in direction 1 Answer
2d rigidbody jump not working 1 Answer