2D Mobile Game: Player Speed
Mar 14, 2022
Intro
In this article, we will quickly go over how to adjust the player’s movement speed.
The Code
The first thing we will want to is create a float variable called _speed withe a SerializedField, so we can adjust the variable in the Inspector while still keeping it private.
In the Movement method, we are simply going to multiply the horizontalInput value by the value of _speed. Since we are getting the Raw Axis value, the horizontalInput will either be -1 (moving left) or 1 (moving right) multiplied by the _speed value of 3 will give the player a speed of 3 units per second in either direction.