Game Development Reference
In-Depth Information
AddToInventory(4, test);
}
When we click on the left mouse button, we create a new GameObject. We set the
new GameObject's name to
"Sword"
. Then we call the
AddToInventory
function,
passing
4
and
test
. Here,
4
is the amount that we want to add to the item count and
test
is the new GameObject that we want to add. Now, run the scene and press
I
. Once the GUI is visible, click on the left mouse button a few times. Your screen
should look something like this:
As you can see, the new item is placed in our inventory. The name of the object as
well as its amount is shown. Now, you'll notice that in the
Inspector
panel you have
a lot of empty GameObjects added to the scene. This is because you created mul-
tiple new GameObjects within your test code. Your
Inspector
panel should look like
what is shown in the previous screenshot as well.