Building UI Elements
--
It’s fairly straightforward to put together a working user interface system thanks to Unity’s Canvas mechanics. As you can see pictured above, you can create multiple scenes, one dedicated as your build settings root index to be your main menu, and one for the actual level/gameplay (or more if you plan on handling many levels, like we expect in Sovereignty). The various UI elements are text or images, and they are directly placed on the canvas, sized and scaled to the screen/viewport/camera.
For the case of the lives, we leverage an array of Sprites that swap the source image via the UI Manager, and the Game Over screen consists of a Game Manager working in tandem with the UI Manager to acknowledge the state of a player without any lives remaining.
The return key to restart the game / load the initial scene was fairly straight forward as well.
Adding a user’s score was leveraged on the Enemy’s script, since that’s where we detect the collisions between lasers and enemies.
The player script itself had very little to modify in order to be able to update a score it was tracking for itself:
We had to add the player reference to the Enemy Script, though, so I may want to alter the way that behaves.
In any case, this is good enough to get things functional for a prototype. Beyond this, we also need to add some basic post processing to give the game more polish and give it a feel of completeness.