Creating a HUD (part 2)
Toggling on and off the Key and Winged Boots icon on the HUD
Now that we have our HUD in place, it is time to make the two icons we designed in Illustrator to show up on the HUD once you buy the corresponding item.
HUD UI prep:
By default the two icons is going to be turned off. We previously had imported and slice the two icons already (if not, go ahead and complete that). Then we will insert them into the HUD UI panel.
Merchant NPC script:
In the Merchant script, we are going to get two “Game Object” handles for the two icons.
Then in the “Buy Item” public method, we are going to individually insert these game objects and turn them on according to what the player has bought. We do this within the switch statement where we can call the icon handler and make that game object active.
Now back in Unity, when we try to buy an Key or boot item, we can see that the icon is turned on.
Turning off the Main HUD:
If you have noticed, when you have toggle the shop UI, the main HUD and touch controls (which we will create in a later article) are overlapping.
To solve this, we will follow a similar method just like how we turned on the keys and boots icon, we can also turn off UI as well.
Currently within our Merchant script, we have our On Trigger Enter script controlling the shop UI pop up. Within the same method we can also turn off the main HUD by giving the HUD game object a handle within the Merchant script and setting it to be deactivated during the Shop UI is turned on.
We then do the exact opposite when the player leaves the shop.
If you have noticed, I also added in a Fader Animator with the parameter of “Fade Out” when the Main HUD disappears and reappears. The fader is controlling the Touch UI (again which we will go into at a later article). But for now we can see what the results would look like.