WepsTech
The world of development
If you are looking for this issue then I make sure then you have done with the official unity tutorial. In the official tutorial they have described everything but at the end, they have missed how you can run your game on the android device.
For the official tutorial “CLICK HERE”
There is small code for android or iOS device which make your game running into the touch device. So let’s have look on that code!.
This is the FixedUpdate()
function code. You will find FixedUpdate()
into your PlayerController
.
private void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
Here add one more function below that!.
void OnTouchDevice()
{
float moveHorizontal = Input.acceleration.x;
float moveVertical = Input.acceleration.y;
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed * 2);
}
Call this function from the FixedUpdate()
. Now your FixedUpdate()
will look like –
private void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
OnTouchDevice()
}
This change will perfectly work for your device!.
Note : This is just a normal change for more deeply you can try a different kind of modification as per your requirement. Try those and enjoy that.
Good Luck 🙂 Happy Coding