We want the objects in the game to move down the lanes (towards the player) at a constant velocity. Create script named MovingObject.cs that will be attached to the Good prefab (available in the Prefabs folder in the starter package), which will act as ‘power-ups’ in the game.
If you drag an instance of the Good prefab into your scene, the object will forever move in one direction. Add the following code to make the object come back to the beginning of the lane tracks and pick a random lane to continue along:
The Bad prefabs will act as the player’s obstacles in the game and also need to move the same way as the power-ups do. Create a Spaceship.cs script that is nearly identical to the MovingObject.cs script we just made, but add a line of code to make the spaceship rotate as it moves down the track: