So I’m creating an inventory system for my game, and I’m having an issue with the image not updating.
So I have a class with a constructor
public Item(string slug)
{
this.Slug = slug;
this.Sprite = Resources.Load<Sprite> ("Art/" + slug);
}
and this function
public void AddItem (int id)
{
Item itemToAdd = database.getItemByID (id); //gets item from database
for (int i = 0; i < items.Count; i++)
{
if(items*.ID == -1)*
-
{*
_ items = itemToAdd;_
* GameObject itemObject = Instantiate(inventoryItem);*
_ itemObject.transform.SetParent(slots*.transform);
itemObject.GetComponent().sprite = itemToAdd.Sprite;
itemObject.transform.position = Vector2.zero;
break;
}
}
}*
But when I run and debug my game, the image is blank and has not loaded.
From what I have found it is an issue with the Image Source not loading the image and staying null, which means the this.Sprite = Resources.Load<Sprite> ("Art/" + slug); line is not working in the constructor.
Any help would be appreciated!_