Creating a Game Manager

Letting the Game Manager Control the Win condition

After creating the UI Manager, we are going to create a Game Manager to handle the transaction between the shop bought objects and pseudo player inventory. The pseudo inventory is invisible to the player but the game manager would keep track of all the objects brought from the stop. For this example we are going to use the Castle Key as the store bought object.

Creating the Game Manager:

Create a new C# script called “Game Manager”, then create a new empty game object in the Hierarchy to place the game manager script.

in Unity 2020 or higher, Unity would recognize a Game Manager script and would automatically change its icon.

Just like the UI Manager we are going to convert our Game Manager into a Singleton script. This would allow all other scripts to gain access to the Game Manager’s properties.

Then we are going to give several public bool variables called “ Has Castle Key, Has Flame sword, and Has winged Boots”. As the name suggest these bools would control whenever the player has purchased the store objects. By creating them in a auto-property we are able to get and set their states in the other scripts.

Merchant NPC Script:

In the Merchant NPC script within the Buy Item method, we are going to create a new switch function with the focus of the selected item as our variable. And just like how we created the switch logic for the Item Select earlier, we will follow the same format and have our case 0 be the Flame sword, case 1 would be the winged boots and case 2 be the castle key. Within these individual case logic we will state the public bool from the Game Manager.

Testing the Game Manager:

To test the game manager and see if the pseudo inventory is working we are first going to enable “Debug” Mode in Unity. At the top right in the Inspector, under the 3 dotted icon, we are going to click and select the Debug Mode. This would allow the Inspector to show hidden values including the pseudo inventory.

By Default the pseudo inventory would be unchecked.

As you can see, once the player buys the selected item within the shop, we can see in the inspector Game Manager script that all 3 items are within our pseudo inventory.




A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

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

Recommended from Medium

Part 6 — Policies in RESTful APIs

What is AWS? — Let’s build the Fundamentals!

Free Online Games To Learn CSS

C++ program to implement multiplication table

6 table is given here

Codeless Automation: The Future or Overhyped?

Introducing ezHub — the Leading GameFi & P2E Tools for Players and Guilds

Protecting against large GraphQL query attacks

Python print colored message on command line terminal window

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
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

Creating the Main Menu

The Fourth Player Challenge: Problem Solving and Jumping

High Definition Rendering Pipeline in Unity

2D Mobile Game: Multiple Tilemaps