O'Reilly logo

Unity Game Development Scripting by Kyle D'Aoust

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required