So im trying to implement staking in my game this is my item script
using UnityEngine;
/* The base item class. All items should derive from this. */
[CreateAssetMenu(fileName = "New Item", menuName = "Inventory/Item")]
public class Item : ScriptableObject
{
new public string name = "New Item"; // Name of the item
public Sprite icon = null; // Item icon
public bool showInInventory = true;
public bool isStackable = true;
public int itemID;
public int itemCurrentStack;
// Called when the item is pressed in the inventory
public virtual void Use()
{
// Use the item
// Something may happen
}
// Call this method to remove the item from inventory
public void RemoveFromInventory()
{
Inventory.instance.Remove(this);
}
}
And my inventory script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Inventory : MonoBehaviour {
#region Singleton
public static Inventory instance;
void Awake ()
{
instance = this;
}
#endregion
public delegate void OnItemChanged();
public OnItemChanged onItemChangedCallback;
public int space = 10; // Amount of item spaces
// Our current list of items in the inventory
public List<Item> items = new List<Item>();
// Add a new item if enough room
public void Add (Item item)
{
if (item.showInInventory) {
if (items.Count >= space) {
Debug.Log ("Not enough room.");
return;
}
items.Add (item);
if (onItemChangedCallback != null)
onItemChangedCallback.Invoke ();
}
}
// Remove an item
public void Remove (Item item)
{
items.Remove(item);
if (onItemChangedCallback != null)
onItemChangedCallback.Invoke();
}
}
I thought the best way to do this was to check if an ID was already in the inventory if it was to the number in the text component on the gui but idk how to do that. help