if(!Input.touchSupported)
{
float x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
Vector2 newPosition = rb.position + Vector2.right * x;
newPosition.x = Mathf.Clamp(newPosition.x, -mapWidth, mapWidth);
rb.MovePosition(newPosition);
}else{
var touch = Input.GetTouch(0);
var touchPos = touch.position;
var isRight = touchPos.x >= Screen.width / 2f;
Vector3 position = rb.position;
if(isRight){
rb.MovePosition(position+new Vector3(0.1f,0,0));
}else{
rb.MovePosition(position-new Vector3(0.1f,0,0));
}
}
As you can see when I am using this application to computer it doesn’t move after Main Camera
. But, when I am running the application in Android. It is moving everywhere. How can I stop the player
if it is not inside Main Camera
?