Another type of input that mobile has, that PC doesn't, is the accelerometer. This allows you to move in game by tilting the physical position of the phone. The most popular example of this is likely the movement of the player in games such as Lima Sky's Doodle Jump and Gameloft's Asphalt series. To do something similar, we can retrieve the acceleration of our device using the Input.acceleration property and use it to move the player. Let's look at the steps to do just that:
- We may want to allow our designers to set whether they want to use this mode, or the ScreenTouch we used previously. With that in mind, let's create a new enum with the possible values to place in the PlayerBehaviour script above the Swipe Properties header:
[Tooltip("How fast the ball moves forwards automatically")]
[Range(0, 10)]
public float rollSpeed = 5;
public enum MobileHorizMovement
{
Accelerometer,
ScreenTouch
}
public MobileHorizMovement horizMovement...