Daily progress: Creating a UIManager

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!

--

--

--

cartoonist, game artist, and wanabe gamedev.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to integrate InfluxDB with AWS

Raising a Developer

Lachie’s 7 step guide to writing a winning tech conference CFP

Why everyone should learn how to code

Dynamic Arrays

Installing Mozilla TTS on a Raspberry Pi 4

A Raspberry Pi 4 on a desk plugged into a power supply

4 Recommendations of Arduino Types for Beginners

Uno R3 DIP Arduino

The Future of Software Delivery is Code. And It’s Here

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Esteban Ibarra

Esteban Ibarra

cartoonist, game artist, and wanabe gamedev.

More from Medium

Adding shields to some enemies

Creating a cooldown system in Unity.

How I used scriptable objects to build a powerup system

Creating Elevator in Unity — Part 3: Moving Elevator.