How to make a controlled jump with a space in Unity? It is necessary that the longer you hold the space, the higher the character jumped. I sort of did it, but the height of the jump is constantly different, I don’t know why this happens. I wish it worked fine.
isGround = Physics2D.OverlapBox(player.position + new Vector3(0, 0.01f, 0), new Vector2(0.065f, 0.01f), 0, LayerGround); if (isGround && Input.GetKeyDown(KeyCode.Space)) { maxYpos = player.position.y + JumpHeight; isJump = true; } if (player.position.y > maxYpos || Input.GetKeyUp(KeyCode.Space)) isJump = false; if (isJump) rb.AddForce(new Vector2(0, JumpPower));