Question by
Cjmarkham · Sep 11, 2015 at 10:39 PM ·
unity 52dbutton trigger events
Hold to jump higher
I have the following code that I have written in order to make a character jump higher if the jump button is held down.
The character performs the initial jump fine but the statement around the button holding never gets triggered since Time.time
is not greater than lastJumpTIme
. Its obvious that I have gone wrong in my calculations somewhere, I just dont know where.
private void HandleJumping() {
if (grounded && ! crouching) {
if (Input.GetButtonDown ("Jump")) {
force = jumpForce;
lastJumpTime = Time.time + 0.5f;
}
}
if (lastJumpTime != 0f) {
Debug.Log (Time.time.ToString () + " - " + lastJumpTime.ToString ());
}
if (Input.GetButton ("Jump") && force != 0f && Time.time > lastJumpTime) {
//force += 100f;
Debug.Log ("HIGH");
}
if (grounded) {
lastJumpTime = 0f;
}
if (force != 0f) {
rb2d.AddForce (new Vector2 (0f, force));
force = 0f;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612033406im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2D Colliders and Raycast miss collision 0 Answers
diffuse shaders cause occasional vertical lines in 2d maps 0 Answers
How to check if player is rapidly rotating the joystick? 2 Answers
UI does not work in build 0 Answers
[NOOB] Unity pixel per Unit? 1 Answer