UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"create an inventory system that is easy to customize from the Unity UI"
using UnityEngine; using System.Collections.Generic; using UnityEngine.UI; [System.Serializable] public class InventoryItem { public string itemName; public Sprite itemIcon; } public class InventorySystem : MonoBehaviour { public List<InventoryItem> inventoryItems; public GameObject inventoryPanel; public GameObject inventorySlotPrefab; private void Start() { PopulateInventory(); } void PopulateInventory() { foreach (InventoryItem item in inventoryItems) { GameObject newSlot = Instantiate(inventorySlotPrefab, inventoryPanel.transform); newSlot.GetComponentInChildren<Image>().sprite = item.itemIcon; newSlot.GetComponentInChildren<Text>().text = item.itemName; } } } /* To customize the inventory system, simply add or remove items from the "inventoryItems" list in the Unity UI. Each item should have a name and an icon. The inventory system will automatically create slots for each item in the list and display their names and icons. */