Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [CreateAssetMenu(fileName = "New Inventory", menuName = "Inventory System / Inventory")]
- public class InventoryObject : ScriptableObject
- {
- [SerializeField] public List<InventorySlot> Container = new List<InventorySlot>(4);
- public void AddItem(ItemObject _item, int _amount)
- {
- if (Container.Count > 0)
- {
- for (int i = 0; i < Container.Count; i++)
- {
- if (Container[i].itemContained.itemName == _item.itemName)
- {
- if (Container[i].itemContained.stackable == false)
- {
- Container.Add(new InventorySlot(_item, _amount));
- break;
- }
- else
- {
- Container[i].amount += _amount;
- break;
- }
- }
- else
- {
- Container.Add(new InventorySlot(_item, _amount));
- }
- }
- }
- else
- {
- Container.Add(new InventorySlot(_item, _amount));
- }
- }
- void RemoveAmount(ItemObject _item, int _amount)
- {
- for (int i = 0; i < Container.Count; i++)
- {
- if (Container[i].itemContained == _item)
- {
- Container[i].amount -= _amount;
- }
- }
- }
- public class InventorySlot
- {
- public int amount;
- public ItemObject itemContained;
- public InventorySlot(ItemObject _item, int _amount)
- {
- amount = _amount;
- itemContained = _item;
- }
- public void AddAmount(int _amount)
- {
- amount = _amount;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement