Shop System with GameManager- Game Dev Series 113

Objective: using GameManager to make Player got what it bought.

In this article, we will make the shop functional with trading.
We have created a shop system with 3 items on the list and interactable. Now we need to make them can actually affect the Player.

GameManager to hold the item

First let’s create a singleton GameManager with 3 getter setter bool methods. These 3 methods would be store the effect that Player bought from shop.

These bool methods would be used in ShopSystem and Player scripts.

Purchase selected item

In the last time we create the purchase method in ShopSystem script, it only costs the price of items. Now we can add a switch statement to make it actually works.
Open ShopSystem and create a switch statement to call GameManager depends on selected item.

With this statement, when Player purchase an item, it would call GameManager to sign it as true.

Check the status from Player

Now we need to make our Player can get the item we bought. Before that, we need to create that item first, then we can turn it on by using bool of GameManager. In this article, I would use Flame Sword as example.
Create a flame sword swinging animation and assign it in Animator with unique trigger.

Once done, create a new bool to check if we get the flame sword. Then use this bool into the line that proceed attack animation as another condition to that if statement.

And we need another method to check if GameManager has mark these items workable(true of bool).

Now, after we call this method from Update(), it would be checked every frame. If we bought the item, we could use it immediately.

And this is how to make the shop functional with GameManager.



A passionate gamer whose goal is to work in video game development.

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
S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.