mirror of
https://github.com/DerTyp7/harvestdale-unity.git
synced 2025-10-29 04:42:08 +01:00
a
This commit is contained in:
34
Assets/Scripts/Inventory.cs
Normal file
34
Assets/Scripts/Inventory.cs
Normal file
@@ -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<Item> items = new List<Item>();
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user