Game Development Reference
In-Depth Information
Using our custom inputs
To access the inventory, we have set up a couple of inputs for our player to use
to view the inventory. Let's add an Update function along with some code that will
show the inventory:
void Update()
{
if(Input.GetButtonUp("I_Key") ||
Input.GetButtonUp("A_360"))
{
showInventory = (showInventory) ? false :
true;
}
}
In the Update function, we check whether the "I_Key" or "A_360" inputs are
pressed. When one of the inputs is pressed, we switch the showInventory
Boolean. When the showInventory Boolean is true , we show the inventory GUI
to the player; if it is false , then we hide the inventory GUI.
Displaying the GUI
Now let's add the OnGUI function to the script, just below the Update function:
void OnGUI()
{
if(showInventory)
{
inventoryRect = GUI.Window(0,
inventoryRect, InventoryGUI, "Inventory");
}
}
Search WWH ::




Custom Search