Daily Progress: Writing a Game Manager.
Yesterday, we created a system to purchase an item but we don’t have a way to reward our player anything yet. A GameManager will be the perfect entity to do that, so let’s create a script called GameManager
As this is a manager style script, we’ll make it a singleton.
In order for this game manager to work, we’ll have to create an empty and then attach this script to it.
Right now, we’re mostly concerned about giving our player the key to the castle, but later we can create other objects:
In GameManager:
We now can keep track of an item the player is given! So let’s go to the shop and make it happen!
In ShopKeeper:
This is yesterdays shopkeeper code we wrote, I just added an if that checks if the currently selected item is #2, which is the key to the castle; if it is, then We’ll set the hasKeyToCastle boolean to true in the GameManager.
We can’t really see variables in the game manager by default, so we’ll have to activate debug mode for it.
So let’s see it in action!
The player has 100 diamonds and is able to purchase the key to the castle, and once they do and we check the game manager, we see it is indeed checked!
Mission accomplished! Our game manager is now successfully keeping track of items player buys and we’ll be able to check if the player has the key once they reach the castle gates!