Actually the name is the problem. The code is as follows:
private bool isGrounded = true; private bool isAir = false; private void Update() { if (isGrounded) State = CharState.Idle; if (isGrounded && Input.GetButtonDown("Jump")) Jump(); //if (isAir && Input.GetButtonDown("Jump")) DoubleJump(); //if (isGrounded && Input.GetButtonDown("Jump + Jump")) DoubleJump(); } private void Jump() { if (Input.GetButtonDown("Jump")) DoubleJump(); else { rigidbody.AddForce(transform.up * jumpForce, ForceMode2D.Impulse); } //rigidbody.AddForce(transform.up * jumpForce, ForceMode2D.Impulse); //isAir = true; isGrounded = false; } private void DoubleJump() { rigidbody.AddForce(2 * transform.up * jumpForce, ForceMode2D.Impulse); //isAir = false; //isGrounded = true; }
The last attempt was like this, but when activating the Jump method, the character immediately goes into the DoubleJump, although it should be wrong.
Jump()
method is executed, in which exactly the same check leads to theDoubleJump()
call. It turns out at some point you click on the "Jump" button, so both conditions are met and the code proceeds toDoubleJump()
. - Mikhail Deyman