Hey guys! I recently finished a very simplistic game that is basically, avoid the oncoming vehicles. Now on windows I have it set so that I simply use the left and right arrow keys to make the player (believe it or not) move left or right. My question is what would be the best way to implement a set of controls for my android phone so that I could move on that too.
This is the current code I am using for windows :)!
using UnityEngine;
using System.Collections;
public class vehicleController : MonoBehaviour {
public float carSpeed;
public float maxPos = 3.6f;
public bool hasAddedSpeed = false;
Vector3 position;
public uiManager ui;
void Start ()
{
//ui = GetComponent<uiManager> ();
position = transform.position;
}
void Update ()
{
if(!hasAddedSpeed)
{
if(ui.score >= 10)
{
carSpeed = carSpeed + 2;
hasAddedSpeed = true;
}
}
position.x += Input.GetAxis ("Horizontal") * carSpeed * Time.deltaTime;
position.x = Mathf.Clamp (position.x,-maxPos,maxPos);
transform.position = position;
}
void OnCollisionEnter(Collision col)
{
if(col.gameObject.tag == "Enemy Car")
ui.Dead();
}
}