Day 8 and 9: Unity UI system and the Singleton design pattern

Objective: To utilize Unity’s robust UI system to create the menus and related player data. We will also user a singleton class for the UI Manager object.
To use Unity’s UI system we can simply choose a UI object to create in the hierarchy. When you decide on what UI objects to create you will automatically create a UI Canvas as well as an event system manager.

We will create a UI manager script and attach it to the canvas object. In this class we need hooks to the UI we will be updating as well as any other UI related item.

First we’ll need to utilize the Using UnityEngine.UI directive. With this library we can access the UI object keywords.
We don’t want to have to keep recreating the UI Manager object(the UI canvas). So we will utilize a singleton class since we will never have more than 1 UI manager. Making this class a singleton instance we will be able to access this object’s public methods globally from all classes in the project.

The player script updates the health as well as the score. The player will call the global public methods in the UI manager class.

We create the methods we need to update the game’s UI. The player class will call these methods at certain times during gameplay by simply calling the UIManager.instance object.


Also, we added this flickering behavior to the Game Over text.