- Home /
How to switch JUMP BUTTON(SPACE KEY) into VIRTUAL BUTTON ON THE SCREEN?
How to make player to jump on click on the button. Player is jumping on the SPACE KEY, so can I switch SPACE to VIRTUAL BUTTON?
You'll have to make your own input manager and call it ins$$anonymous$$d of Input.etc, alternatively there are a couple free assets available such as CN Controls
Answer by abdo400 · Aug 26, 2017 at 06:13 PM
Yes, write a public function, maybe in the player script. Then drag the player gameObject - the object that the player script is attached to - to the button and select the jump function.
Answer by vanjasretenovic123 · Aug 26, 2017 at 08:44 PM
I'm a beginner, so I didn't understand it. Can you explain everything gradually to me? I made button and I have this script
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq;
using UnityEngine.EventSystems; using UnityEngine.UI; public class Jump : MonoBehaviour { public float force; public Rigidbody player; public bool isFalling;
void Start()
{
player = GetComponent<Rigidbody>();
isFalling = false;
}
void Update()
{
if (isFalling == false)
{
if (Input.GetButton("Jump"))
{
player.AddForce(transform.up * force);
isFalling = true;
}
}
}
private void OnCollisionStay(Collision collision)
{
isFalling = false;
}
}
What I need to do now? Thank you in advance!!!