I have made these buttons to make this game’s controls compatible for android and below is my playermovement script I want to make my UI buttons in screen such that when I use buttons it feels like controlling through two keys of key board
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityStandardAssets.CrossPlatformInput;
public class PlayerMovement : MonoBehaviour {
//This is a reference to the Rigidbody component called "rb"
public Rigidbody rb;
public float forwardforce = 200f;
public float sidewaysforce = 500f;
public float upwardforce = 600f;
public int Start()
{
Scene currentScene = SceneManager.GetActiveScene();
return currentScene.buildIndex;
}
// We marked this as "Fixed Update"because we are using it to mess with physics
public void FixedUpdate() {
rb.AddForce(0, 0, forwardforce * Time.deltaTime); //Add a forward force
if (Input.GetKey("d"))
{
Debug.Log("Right");
Right();
}
if (Input.GetKey("a"))
{
Debug.Log("Left");
Left();
}
if (Start() == 5)
{
if (Input.GetKey("w"))
{
rb.AddForce(0, upwardforce * Time.deltaTime, 0, ForceMode.VelocityChange);
}
}
if (rb.position.y < -1f)
{
FindObjectOfType<GameManager>().EndGame();
}
}
public void Right()
{
rb.AddForce(sidewaysforce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
public void Left()
{
rb.AddForce(-sidewaysforce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
}
Please help me and thanks in advance to whoever helps