Game Development Reference
In-Depth Information
11. To display UI textures and elements on the screen, Unity provides a special
callback method to place our UI code whenever the UI is refreshed. This
method is called OnGui() and has the following signature:
void OnGUI(){
}
12. We invoke our DisplayInventory() method inside the void OnGUI()
method that Unity provides because this method draws the Invent-
oryItems list of InventoryMgr to the screen in the form of UI buttons. This
callback is where all drawing and GUI-related processing occurs, as shown
in the following code:
void OnGUI()
{
DisplayInventory();
}
We could modify this code slightly to draw the maximum number of cells in
the inventory rather than the total number of filled InventoryMgr cells. We
must be careful to not dereference past the end of the collection if we have
been doing so!
Congratulations! We now have a working InventoryMgr system that can interface
with interactive objects and collect them based on their custom type! While we
touched briefly on the MissionToken class in this explanation, we need to develop
a system for tracking the abstract mission objectives and rewarding the player on
achieving success. This requires multiple classes. The result of performing these
steps is shown in the following screenshot:
Search WWH ::




Custom Search