Creating a Game Manager

Letting the Game Manager Control the Win condition

Simon Truong
3 min readDec 26, 2021

--

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.

--

--

Simon Truong

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