Book Image

Unity Game Development Scripting

By : Kyle D'Aoust
Book Image

Unity Game Development Scripting

By: Kyle D'Aoust

Overview of this book

Table of Contents (17 chapters)
Unity Game Development Scripting
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Removing items


Now, we'll add the second most important aspect of inventories, removing items! This is handy for those times when a player uses their health potion, sells an item, shoots a rocket, or drops their coins!

Let's figure this out

Just like we did when we added items, let's take a moment to think about how we want to remove items from the inventory. Again, from the player's point of view, how is this done? Well when they sell the item, they are selecting the item personally. If the player shoots their gun or bow, their ammo is dispensed immediately. When the player meets their untimely death, their items may be dropped on the ground or left on their corpse to be looted by their assailant. During the selling item phase and shooting gun action, they pick what item they want to get rid of from their inventory. We will follow a similar process when removing items from the inventory.

Creating the removing function

Add the following function to the script, just below the AddToInventory function...