Game Development Reference
In-Depth Information
Setting the quick-select items
In many games, there is a mechanism known as quick-items or quick-select items.
These are items that the player uses often and wants to have access to very quickly
without having to stop the game to go into their inventory. They are typically accessed
by the number keys on the keyboard or the directional pad on a controller. We will add
a small function into our inventory that will allow us to assign quick-items.
Setting the quick-select items quickly
Add this function to your script, under the RemoveFromInventory function:
void SetQuickItem(GameObject NewItem, int
QuickInput)
{
if(QuickItems[QuickInput].name != NewItem.name)
if(QuickInput < QuickItems.Length)
QuickItems[QuickInput] = NewItem;
}
This function takes in two variables, the GameObject that we want as the quick-item
and the slot that we want to assign it to. In the actual function, we check whether the
name of the GameObject in the current QuickItems array is the same as the name
of NewItem . If it is not same, then we will not do anything because the item is already
in that quick-item slot. If it isn't, then we assign the QuickItems array slot, which is
QuickInput , to the GameObject passed into the function.
Let's display the inventory
Now let's move on to the next important aspect of the inventory, showing it to the play-
er! To do this, we will use GUILayout and a GUI window.
Search WWH ::




Custom Search