Setting the Score
The first step in building my UI system is setting up a system to keep track of the player’s score. To start, I need to create a UI element that displays the score on the screen. I did this by creating a new Text UI element in the Hierarchy. Once established, I can then move the text to the upper right corner of the screen. I can then anchor the text to the corner and have it move and scale with the size of the display.
Now to set up the logic for the scoring system. I created a script that manages the changes to the UI, and set up the Player and Enemy scripts to communicate. Whenever an enemy is destroyed by a laser, there is now logic that tells the player to increase it’s score by 10. The Player script then communicates to the UI manager to increase the score on the screen appropriately.