- Home /
Question by
markisakov57 · Jun 18, 2019 at 04:43 AM ·
inputmobile devicesinput.touch
Can someone help with mobile input on my game?
I made a 3D game in which you move automatically forward but you control the X axis (left and right). I need help with making touch controls. When I touch the left side of my screen i move left and when i touch the right side i move to the right. It's not like subway surfers with lanes but free movement. If someone could explain how (in C#). Thanks! This is my normal script.
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public Rigidbody rb;
public float forwardForce = 2000f;
public float sidewaysForce = 500f;
void FixedUpdate()
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetKey("right"))
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey("left"))
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (rb.position.y < -1f)
{
FindObjectOfType<GameManager>().EndGame();
}
}
}
Comment