Jump when you press on-screen button


Would anyone be kind enough to explain to me how i could make a button that makes a player jump when clicked in C#?

Im using a character controller, not rigidbody.
Also please dont just write the script for me, im trying to learn and just copy-pasting is not going to help.

Whenever i try to do it, it either doesnt make me jump at all or i can jump repeatedly in mid-air even though i used isGrounded to check if the player is not in the air.

I know how to do it when you for example press the space button, but i need it to work when a button on screen is clicked.

Thank you in advance

If you manage when you press the space key then it’s the same !

Put the Jump() methos in public And in your button, drag and drop the player script to the event sections (OnClick) and select the Jump method !

The isGrounded check goes inside the function !