I am practicing with creating a 2D-Game and I write the C#-script code but my character can't jump.
I try to replace "Space" with "UpArrow" that also didn't work.
if (Input.GetKey(KeyCode.UpArrow) && onGround)
{
rb.velocity = new Vector2(rb.velocity.x, jumppower);
}
Nothing Happen. Character can'r move Right and Left but not jump.
Some items to start with:
Debug.Log($"is on ground {onGround}")
before the if and check it.Then I see a logic issue. This is what happens in your code:
To solve this replace this line:
rb.velocity = new Vector2(rb.velocity.x, jumppower);
With this:
rb.AddForce(new Vector2(0, jumppower), ForceMode2D.Impulse);