- Home /
how do i make my Playeer jump via UI Button?
I'm trying to see how I can make my player (Cube) jump by pressing a button. I have been trying to make this happen for the past week but have gotten nowhere. please if you have any ideas how to help please let me know.
this is what my Scene looks like if that helps: (the joystick controls are only left and right movement (Cube moves Continuously forward) and the button if the left button corner is my jump button)
Answer by Prastiwar · Dec 21, 2017 at 08:24 PM
Do you have any code? What's your problem? Jumping code or adding code to button? Adding listener to button is pretty simple, just make method in script and add it to "OnClick" function in button component.
To make a jump, just add force to your cube. Don't know how would you like to make jumping system (double jumping or just one etc.) I'll give you example of just adding "jump force" to player.
Rigidbody playerRB;
float force = 50; // random number, you have to test it
public void OnJumpButton() // like this
{
playerRB.AddForce(Vector3.up * force);
}
public void OtherOnJumpButton() // or like this
{
playerRB.velocity += Vector3.up * force;
}
thanks it makes my player jump but it doesn't stop jumping... do you know of anything I can do?
Your answer
Follow this Question
Related Questions
"No appropriate version" error 2 Answers
Jumping while moving 1 Answer
How do I script Street Fighter style movement? 1 Answer