Shop Market Displays Players Gems

addam davis
3 min readDec 16, 2021

Objective: Create the feature for the shop to know and display the players current gem count.

Previously we created a button with the intension of displaying the players gem count and for visual reasons we entered 54G as a place holder. In this tutorial we are going to attach our player’s diamonds to this and display accordingly.

To begin we need a text variable on our UI manager for the players gem count.

In unity, select the Canvas object and in the inspector under the player gem count text assign the text object childed under the player gem count UI element.

Now when we open the shop we want to set the amount using a parameter for the player’s gems amount.

When are we calling this method? From the shopkeeper script, when the player collides with the shop opening the panel. We gain a reference to the player and using that we can get their diamond count and send it to the UI.

Now when we open the shop the display will show how many diamonds the player has collected.

We can take this a step further with updating the price when we buy and item. Create a reference to the player.

Then we need to create a method to be called when the player buys an item to adjust the players gem count.

Now the player’s gem count will update if we purchase an item.