Android mobile device ontouch

how can i divide my ontouch on my screen for example my character is on the center of the screen and i want to divide the ontouch on both left and right from its center. so that what happens is my character will face in that direction.

PS anywhere on the left or right screen can be clicked so that my character can turn to its side thanks for help!

You need to base your decision on the screen width.

if (touch.position < Screen.width/2) {

// turn left, for example with a statement like this:
transform.forward = Vector3.left;

}

if (touch.position > Screen.width/2) {

// turn right, for example with a statement like this:
transform.forward = Vector3.right; 

}
  • Where transform.forward is the forward vector of your gameobject you want to face in the certain direction. It may also be transform.right, just try it out. It’s just the ‘side’ of your gameobject you want to be faced towards a certan direction.