Hello. As the title says, I’m in need of creating an RPG inventory system that supports storing several of the same item with an item count (think Bethesda titles on the Gamebryo/Creation engines). Searching for tutorials on this only result in ARPG-esque or single-item-per-slot approaches, which doesn’t provide all the solutions I’m looking for.
Currently, this is what I’ve set up as a proof of concept to iterate upon later:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerManager : MonoBehaviour
{
public List<Item> playerInventory = new List<Item> (50);
public float playerWeight;
public void AddItemToInventory(Item itemToAdd)
{
if (itemToAdd.itemID != null)
{
playerInventory.Add(itemToAdd);
}
else
{
Debug.Log($"{itemToAdd} is an invalid item.");
}
}
public void RemoveItemFromInventory(Item itemToRemove)
{
if (playerInventory.Contains(itemToRemove))
{
playerInventory.Remove(itemToRemove);
}
else
{
Debug.Log($"{itemToRemove} does not exist in the player's inventory.");
}
}
}