Daily progress: Creating a UIManager

Esteban Ibarra
3 min readAug 28, 2021

When we enter the shop, we have the shop code already that will deal with the display of the shop menu and its options, but we’ll also need a manager that will handle the gem economy of the game and update menus when gems are spent or claimed; We’ll create a UIManager for this.

First, we’ll create a new directory in our Scripts directory called UI which will contain all the HUD related functions:

Within this directory, we’ll create a script called UIManager

We’ll turn it into a singleton so we can easily access it in the shop:

In UIManager:

Let’s also attach the UIManager to the canvas:

Next, we’ll need to create a holder for the shops' Gem text display; We’ll add this code:

In UIManager:

And then drag the gem text item into the holder:

Our players' diamonds variable is currently private, let’s make it public so the UIManager can access it.

In Player:

Next, we’ll have the shopkeeper access the UIManager and send over the player diamond count, we haven’t written the UIManager code yet, but we’ll do that immediately after this!

In ShopKeeper:

So now we’ll need to create an OpenShop function that gets the diamond integer passed into it:

In UIManager:

We’ll access the gemCountText object and write the current amount of gems/diamonds we have. Currently 0, but let’s see if it works:

0 gems! Looking good! Now let’s see if we change the amount the player has:

I changed the amount to 33 gems and it showed in the shop menu! Excellent!

Tomorrow we’ll go over OnClick events!

--

--