Summary - Inventory
- Game Development course
- Intermediate
- Lesson 78/83
- 4 min
Combine the inventory project with a single summary task.
Inventory Project Summary
In the inventory project, the Item class defines item data. InventoryManager stores these objects using a List<Item> collection. The AddItem and RemoveItem methods manage the collection. The PrintItems method displays its contents using foreach and Debug.Log. Together, these parts form a basic inventory system.
Item → List<Item>
AddItem() / RemoveItem()
PrintItems()Practice Combine the Inventory System
Define an Item list in the InventoryManager class. Add a new item with AddItem, remove an item with RemoveItem, and print every item name using a foreach loop inside PrintItems.
Starter code
using UnityEngine;
using System.Collections.Generic;
public class InventoryManager : MonoBehaviour
{
public List<Item> items = new List<Item>();
// Gerekli metotları sınıfa ekle
}Sample solution
using UnityEngine;
using System.Collections.Generic;
public class InventoryManager : MonoBehaviour
{
public List<Item> items = new List<Item>();
public void AddItem(Item item)
{
items.Add(item);
}
public void RemoveItem(Item item)
{
items.Remove(item);
}
public void PrintItems()
{
foreach (Item item in items)
{
Debug.Log(item.itemName);
}
}
}Expected output
Potion Key Shield
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which combination can be used to store, manage, and display items in a basic inventory system?
- Only Animator and Animation Clip
- Prefab Variant and camera settings
- Only Transform and Rigidbody
- Item, List<Item>, add-remove methods, and foreach Correct answer
Explanation: Item defines the data, List<Item> stores it, methods manage it, and foreach iterates through the contents.
2 Complete the Inventory Data Structure
Envanterde birden fazla Item nesnesini dinamik biçimde saklamak için ____ koleksiyonu kullanılır.
Envanterde birden fazla Item nesnesini dinamik biçimde saklamak için List<Item> koleksiyonu kullanılır.
Explanation: List<Item> dynamically stores multiple Item objects in the inventory.
3 Match the Inventory Project Parts
| Term | Meaning |
|---|---|
Item |
Class defining each item's data |
InventoryManager |
Class managing item collection |
AddItem |
Operation accepting new items |
PrintItems |
Outputs collection contents to console |