How can I make my Player jump when I press a UI button?
Hey guys!
I'm having a bit of a issue on one of my projects. So I'm trying to make my character jump when I press a UI button, but I haven't been able to make it work thus far. I tried adding a Rigidbody to my Player and just doing:
public Rigidbody rb;
public void onJumpButton()
{
rb.AddForce(Vector3.up* jumpForce);
}
and this is on my buttons On Click () function but that didn't work. I already have jumping figured out on the pc and for pc my code is:
if (controller.isGrounded)
{
verticalVelocity = -gravity * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space))
{
verticalVelocity = jumpForce;
animator.SetBool("is_in_air", true);
jump.Play();
}
}
else
{
animator.SetBool("is_in_air", false);
verticalVelocity -= gravity * Time.deltaTime;
}
and this works fine when i press space on PC but I need to incorporate this into a UI button for Cellphone use. If anyone has any tips on how I can do this that would be greatly appreciated.
Thanks for your time!
Comment