How can I make the cube move left n right with mobile buttons or controls
Here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public Rigidbody rb;
public float ForwardForce = 2000f;
public float SideWaysForce = 100f;
float moveVelocity ;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void FixedUpdate ()
{
// Add a ForwardForce
rb.AddForce (0, 0, ForwardForce * Time.deltaTime);
// For PC Control
if(Input.GetKey(KeyCode.RightArrow ))
{
rb.AddForce (SideWaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if(Input.GetKey(KeyCode.LeftArrow))
{
rb.AddForce (-SideWaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (rb.position.y < -1f) {
FindObjectOfType<GameManager> ().EndGame();
}
}
}
Thankyou in advance.