Download unity project here
For milestone 1 I have created a prototype of the games power up system. Powerups are randomly spawned at predetermined locations across the map. When a powerup spawns and is picked up by a player the player or AI they will have to wait for some amount of time, and then the power up will become usable. The player will see his current power up in the HUD, and will also be able to see if he has picked up a powerup and is waiting for it to become active. The systems that make up the prototype are discussed in more detail below.
Powerup Spawning System
PowerUpSpawnPoint gizmos are placed at various locations around the map. A PowerUpSpawnerObject runs a script that randomly chooses a spawn point, then randomly chooses a powerup type (with each powerup type having a certain probability of being chosen). It creates a PowerUp game object at the point it has chosen, and removes that point from the list of points that can be chosen in the future. The frequency in which power-ups are spawned and the probability of each type of power up can be easily changed in the unity editor. Additional powerup types can also be created form the unity editor.
Powerup Manager
The PowerUp, game objects have a collider attached. When an object collides with the PowerUp and that object has a PowerUpManager script attached the power up game object is destroyed, and the type of power-up is passed to the PowerUpManager.
Both the player, and the AI will have a PowerUpManager script attached. The PowerUpManager keeps track of the current powerup available to the player/AI and keeps track of delaying the use of the powerup for some time after it has been picked up. The PowerUpManager manager script can be setup with a reference to the game HUD, if it has this reference it will show its state on the HUD. So the script attached to the player will have this set, while scripts attached to AI will not.
HUD
The game HUD shows the state of a PowerUpManager object. The HUD can show one of three states: "no powerup", "powerup", "or waiting for powerup". The first two states are simple to draw the "no powerup" state is just an empty box, the "powerup" state shows an image for that type of powerup in the box. Images for each powerup can be specified in the Unity editor.
For the waiting for powerup state we want the player to know he is going to be getting a powerup, but not know what it is yet. To do this I show the powerup box spinning through all possible powerup images like a slot machine. This requires drawing only part of an image. Its tricky to get to draw just part of an image using the GUI labels. In order to do this I use the GUI.BeginGroup GUI.EndGroup method to force the GUI to only draw within a small area of the screen. I then draw the part Label so it partly out of that region.
Prototype Gameplay
To use the prototype just use the arrow keys to move the red block around the map. Once every 5 seconds a blue sphere will appear on the map (this is a powerup). Driving into the powerup will cause the player to pick up the powerup, the HUD will show the powerup slot wheel, and after 5 seconds the powerup acquired will show in the HUD. Press space to use the powerup, and the HUD will empty. Note: the powerups do not currently do anything when used.
In the gameplay video below the frame rate is such that you don't get the full effect of the powerup slot. Download the game above to see how it really looks.