Using the accelerometer
Another type of input that mobile has, that PC doesn't, is the accelerometer. This allows you to move as the phone is tilted. The most popular example of this is likely the movement of the player in games such as Lima Sky's Doodle Jump. To do something similar, we can retrieve the acceleration of our device using the Input.acceleration
property:
- First, 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 newenum
with the possible values to place in thePlayerBehaviour
script above theSwipe Properties
header:
public enum MobileHorizMovement { Accelerometer, ScreenTouch } public MobileHorizMovement horizMovement = MobileHorizMovement.Accelerometer;
This gives us a property called horizMovement
and the two possibilities that it can have given to us by the enum
definition that we've made. Now, if you were to save the PlayerBehaviour
script and dive back into the...