For whatever reason jumpButtonDown is always false outside of my OnJump function. I am not sure if I am missing something, or how I can create a variable that tracks when I press the jump button outside of the OnJump function.
public void OnJump(InputAction.CallbackContext context) {
jumpAction = context.ReadValue<float>();
jumpButtonDown = context.started;
if (context.started && (touchingDirections.IsGrounded || jumpsRemaining != 0 && !IsWallJumping && !IsWallSliding)) {
rb.velocity = new Vector2(rb.velocity.x, jumpsRemaining != maxJumps ? doubleJumpeImpulse : jumpImpulse);
jumpsRemaining--;
}
if (context.canceled && rb.velocity.y > 0 && !IsWallJumping && !IsWallSliding) {
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
}
}
private void WallJump() {
if (IsWallSliding) {
IsWallJumping = false;
wallJumpingDirection = -transform.localScale.x;
wallJumpingCounter = wallJumpingTime;
CancelInvoke(nameof(StopWallJumping));
} else {
wallJumpingCounter -= Time.deltaTime;
}
if (jumpButtonDown && wallJumpingCounter > 0f) {
IsWallJumping = true;
rb.velocity = new Vector2(wallJumpingDirection * wallJumpingPower.x, wallJumpingPower.y);
wallJumpingCounter = 0f;
Invoke(nameof(StopWallJumping), wallJumpingDuration);
}
}
private void Update() {
horizontal = moveInput.x;
WallSlide();
WallJump();
if (jumpButtonDown) {
Debug.Log("jumpButtonDown in Update");
}
if (touchingDirections.IsGrounded && !(jumpAction > 0)) {
jumpsRemaining = maxJumps;
}
if (!touchingDirections.IsGrounded && jumpsRemaining > (maxJumps - 2)) {
jumpsRemaining = maxJumps - 1;
}
}