In this recipe, you created a player character in the scene using the girl1 sprite and added a scripted component instance of the PlayerMove class. You also created a star GameObject (a pickup), a tagged star with a 2D box collider that will trigger a collision when the player's character hits it. When you run the game, the player-girl1 character should move around using the W, A, S, and D keyboard keys, the arrow keys, or a joystick. There is a newVelocity variable that is updated each frame in the Update() method based on the inputs. This Vector2 value is then applied to the FixedUpdate() method to become the new velocity for the GameObject.Â
Unity maps user inputs such as key presses, arrow keys, and game controller controls to its Input class. Two special properties of the Input class are the Horizontal and Vertical axes, which can be accessed via the Input.GetAxis ("Horizontal") and Input.GetAxis...