Triple jumping instead of double

Hi, thanks for taking the time and checking out my question. I’m trying to set up a simple double jump mechanic with this script

int jumps = 2;
...
void jumping()
	{
		Debug.Log(jumps);
		grounded = Physics2D.OverlapCircle(groundCheck.position, radius, groundMask);

		if (grounded)
		{
			jumps = 2;
		}

		if (Input.GetButtonDown("Jump") && jumps > 0)
		{
			jumps--;
			rb.velocity = Vector2.up * jumpForce;
		}
	}

this script sometimes works fine but sometimes I’m able to jump 3 times when debugging it showed in the console that whenever I get that case where my player is jumping 3 times it doesn’t subtract when the “jumps” is on 1. it goes like this: 2 → 1 → 1 and finally 0 but it repeated 1 so I jumped 3 times…

Thanks a lot, solutions are deeply appreciated.

When you are animating your jump, there should be an option under Animator or Inspector tabs to change when he falls back down. Maybe try that, or a setting with gravity strength.

Are you calling jumping() in Update()?

Because if yes, then it could just happen that the jumping method is called faster than you actually can click the jump-button.

Maybe move your Debug.Log() from line 5 under line 15 and check again. It’s probably just a logging problem.