From e215afc5348f2a34519be52a02f4d279bb1d7089 Mon Sep 17 00:00:00 2001 From: Janis Date: Mon, 20 Feb 2023 18:37:24 +0100 Subject: [PATCH] a --- Assets/Scripts/Inventory.cs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Assets/Scripts/Inventory.cs diff --git a/Assets/Scripts/Inventory.cs b/Assets/Scripts/Inventory.cs new file mode 100644 index 0000000..06b4ada --- /dev/null +++ b/Assets/Scripts/Inventory.cs @@ -0,0 +1,34 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Inventory : MonoBehaviour +{ + [SerializeField] private int slots = 10; + [SerializeField] private int stackSize = 100; + [SerializeField] private List items = new List(); + + + public Item Add(Item item) + { + foreach (Item i in items) + { + if (i.uuid == item.uuid) // item already is in list + { + if (i.quantity + item.quantity <= stackSize) + {// enough space + i.quantity += item.quantity; + item.quantity = 0; + } + else + {// Not enough space + i.quantity = stackSize; + item.quantity = Mathf.Max(0, i.quantity - item.quantity); + } + } + } + return item; + + } + +}