Ease of Building UI Elements in Unity

Setting up basic UI elements in Unity is fairly easy.
To setup my lives and score UI in my space shooter game I started by right clicking in the Hierarchy and selecting UI>Text

This will create a Canvas with a Text Object below it and an EventSystem in the Hierarchy. Click on the Canvas and under the Canvas Scaler component> UI Scale Mode select Scale With Screen Size. This makes the UI look right when the screen size changes.

Now I changed the name of the Text object to Score_text and then changed the actual text to “Score: 0”. Now I placed it where I want it to be in the screen which is the upper right corner. In order for it to stay here when on different screen configurations you need to anchor it to the upper right by clicking in the box in the Rect Transform component and selecting the upper right one.


Now I created a UI_Manager gameobject in the hierarchy and attached a UIManager script I created to it. This UIManager script will control all of what my UI displays.

In this UIManager script I am subscribing to Actions in my Player script that pass points when I score or current lives when Player is damaged.

The Player script is subscribed to Actions in my Enemy scripts that send their points value to the Player to update the score.


I have variables at the top that I assigned in the inspector for each of my UI elements.

The player lives UI is setup the same only I select UI>Image and then drop in the default sprite which is the 3 lives sprite and set the anchor to upper right.

