- Home /
Database error updating inventory
Hey guys, so im working on an inventory system as a feature for my finals and i currently have a database of consumables, along with this i also have a script called Inventory which has a struct and adds items to our inventory, up until here everything works perfectly. Ofcourse i also have an Items script which has an interface that allows them to be picked up. So essentially, i can pick up items pretty well. My problema comes when im trying to do the UI aspect of things… Im unsure of what is going on and how to fix this, but i want to. Main issue is this right here, "Cannot implicitly convert "Inventory.Items" to Items.
void UpdateUI()
{
int i = 0;
for (; i < inventory.Count ; i++)
{
//Error is here;
itemSlots[i].Items = inventory[i];
}
for(; i < itemSlots.Length; i++)
{
itemSlots[i].Items = null;
}
}
Here is my Items script:
public class Items : MonoBehaviour, IInteractable
{
[SerializeField]
string name;
[SerializeField]
Sprite icon;
TypeOfItem typeOfItem;
public enum TypeOfItem
{
CON,
WEP,
}
public TypeOfItem TypeOfItem1
{
get
{
return typeOfItem;
}
set
{
typeOfItem = value;
}
}
Inventory inv;
public Sprite Icon { get => icon; set => icon = value; }
void Start()
{
inv = Inventory.instance;
}
public void Interact()
{
inv.AddItem(name, Icon,TypeOfItem1);
Destroy(gameObject);
}
}
This right here is ItemSlot:
public class ItemSlot : MonoBehaviour
{
[SerializeField]
Image image;
[SerializeField]
private Items item;
public Items Items
{
get { return Items; }
set
{
Items = value;
if (Items == null)
{
image.enabled = false;
}
else
{
image.sprite = Items.Icon;
image.enabled = true;
}
}
}
private void OnValidate()
{
if (image == null)
{
image = GetComponent<Image>();
}
}
}
Also if it helps anyone figure out the problema, here is the adding to inventory part, i have not included the struct since and some other things such as access to database since its something i dont reckon that needs changing, but if anyone needs to have a look just let me know
public void AddItem(string name, Sprite sprite, Items.TypeOfItem type)
{
//Switch
if(consumableDB.ConsumableReturn(name) != null)
{
inventory.Add(new Item(name, sprite, 1));
UpdateUI();
Debug.Log("Added");
}
}
Its worth noting im inspiring my system on one that i saw on youtube, but i don't want to go the exact same route, i do not want to copy his code so any guidance helps. Thanks for the help/info people.