i have a lot wrong with my inventory, but i’m just going to post one thing i’m having trouble with:
“Array index is out of range”
// need a system of naming for this method?
void ShowMerchant1()
{
string labeltxt = "";
string labelimg = "";
int counter = 0;
for (int i = 0; i < merchant1_capacity; i++)
{
counter = i + 1;
//update icon and text
labeltxt = "M1text" + counter;
labelimg = "M1image" + counter;
Text text = GameObject.Find(labeltxt).GetComponent("Text") as Text;
if (merchant1[i].item == null || merchant1[i].item.objname == "Nothing")
text.text = "Nothing x 0";
else
text.text = merchant1[i].item.objname + " x " + merchant1[i].quantity;
Image image = GameObject.Find(labelimg).GetComponent("Image") as Image;
if (merchant1[i].item == null || merchant1[i].item.objname == "Nothing")
image.sprite = Resources.Load<Sprite>("nothingicon");
else
{
Sprite invicon = Resources.Load<Sprite>(merchant1[i].item.sprite);
image.sprite = invicon;
}
}
}
on line 17
i know i’m not supposed to use GameObject.Find but i don’t know what else i can use
my merchant inventory is set to the same as merchant1_capacity in the inspector
i also have trouble with when i open the store by clicking on the merchant - my icons don’t show up (for the player either; unless i have already opened the inventory to view it, then the icons work for the player but still not the store). however, no issue with the text.