So I am new to coding and Unity in general, so I have been following Brackeys “Making an RPG in Unity” tutorial, and I have come across this error that I can’t find any information online to fix. In episode 6"
" at 1:03 he creates the script inventory.onItemChangedCallback… and when I saved this to unity, It came up with the error
[Assets\InventoryUI.cs(12,19): error CS1061: ‘Inventory’ does not contain a definition for ‘onItemChangedCallback’ and no accessible extension method ‘onItemChangedCallback’ accepting a first argument of type ‘Inventory’ could be found (are you missing a using directive or an assembly reference?]
here is my code… I don’t seem to have any misspellings, so I don’t really know what is going on. Thank you.
using UnityEngine;
public class InventoryUI : MonoBehaviour
{
Inventory inventory;
void Start()
{
inventory = Inventory.instance;
inventory.onItemChangedCallback += UpdateUI;
}
void Update()
{
}
void UpdateUI ()
{
Debug.Log("Updating UI");
}
}
also here is my code from the actual Game Manager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Inventory : MonoBehaviour
{
#region Singleton
public static Inventory instance;
void Awake()
{
if (instance != null)
{
Debug.LogWarning("More than one instance of inventory found!");
return;
}
instance= this;
}
#endregion
public int space = 20;
public List<Item> items = new List<Item>();
public bool Add(Item item)
{
if (!item.isDefaultItem)
{
if (items.Count >= space)
{
Debug.Log("Not enough room.");
return false;
}
items.Add(item);
}
return true;
}
public void Remove (Item item)
{
items.Remove(item);
}
}