Jump only when Jump button is pressed - not held

Hi! Super new to Unity (and programming) here. Hoping to change that though. :slight_smile: I searched all over but couldn’t find an answer that specifically helped solve my issue, so… here goes:

I’m making a 2D platformer. I want my character to jump higher when the button is held down, which is achieved through the following code (in the update function/method).

if (isGrounded) 
			{
				jumpTimeCounter = jumpTime; 
			}

			if (Input.GetButtonDown ("Jump")) 
				{
				if (isGrounded) 
					{
						myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, jumpForce);
						stoppedJumping = false;
					}
				}

			if (Input.GetButton ("Jump") && !stoppedJumping) 
				{
				if (jumpTimeCounter > 0f) 
					{
						myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, jumpForce);
						jumpTimeCounter -= Time.deltaTime;
					}
				}

			if (Input.GetButtonUp ("Jump")) 
				{
					jumpTimeCounter = 0f;
					stoppedJumping = true;
				}

Now, that works great. My problem now is that the character keeps jumping when I’m holding space, which often happens accidentally, making the player jump when he/she didn’t mean to.

How can I make it so that the player can only jump when space is PRESSED, not HELD when using Input.GetButton (which is used to add force to the continued jump)? I experimented with booleans on the Input.GetButtownDown and Input.GetButtonUp, but it seems the code in between those (the Input.GetButton-code) screws this up.

If anyone could help me out with this, it would be hugely appreciated.

All the best

do you have any update on how to fix because i am having the same problem?