Question by
Kasimirplayz · Jul 18, 2018 at 06:44 PM ·
androidmovementbuttonbeginner
How to get on screen buttons to work
I'm new to programming and cant get this to work so i would appreciate some help.`
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public Rigidbody rb;
public void LEFT;
public void RIGHT;
public float forwardForce = 2000f;
public float sidewaysForce = 500f;
void FixedUpdate () {
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetButton(LEFT))
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetButton(RIGHT))
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (rb.position.y < -1f)
{
FindObjectOfType<GameManager>().EndGame();
}
}
} `
Comment