Touchscreen car controls

So I’m developing a game for Android devices. The game is about a taxi in a city.
The car, so far, is fully functional on PC (acceleration, steering) but I’m stuck on a part where I would create on screen controls for touch screen. Just four buttons, 2 for acceleration, 2 for steering. Please help me if You can, because I’m stuck on this part for like 3 days and 3 nights.

I’ve never worked with iOS, however, did you read the scripting reference for the iOS?

Use planes in front of the camera with textures for the buttons. Then, send a ray out from where the player touches the screen. Depending on what plane the ray hits, different things happen.

I have no previous raycast experience, but I’ll try to do this how I just learned it off some google searching :slight_smile:

//In javascript
function Update(){
     for(var touch : Touch in Input.touches){
          if (touch.phase == TouchPhase.Began) {
            var theRay : Ray = Camera.main.ScreenPointToRay(touch.position);
            var hit : RaycastHit ;
            if (Physics.Raycast (theRay, hit)) {
                if(hit.transform.name == "Drive"){ 
                     Accelerate();
                }
                if(hit.transform.name == "Brake"){ 
                     Brake();
                }
                if(hit.transform.name == "TurnLeft"){ 
                     TurnLeft();
                }
                if(hit.transform.name == "TurnRight"){ 
                     TurnRight();
                }

            }
        }

     }

}
function Accelerate(){
      //Do something
}
function Brake(){
      //Do something
}
function TurnLeft(){
      //Do something
}
function TurnRight(){
      //Do something
}

I haven’t tested it in a game, but it compiled without error. Hope it works :slight_smile: