- Home /
Problem is not reproducible or outdated
Having a hard time getting my GUI button which is generated at runtime to work.
Hi,
Im currently working on my inventory system. Im creating slots based on the items in my inventory. I added a button component to the prefab of the item slot and I am adding the listener via code. However I am running into a error: First off unity is only registering about 25% of my clicks on the button. Ive made sure there are no other UI elements blocking the button and ive also put my eventsystem in Force Module Active mode. Ive tried various other solutions from the internet but couldnt find any that worked.
for (int j = 0; j <= inventory.Count - 1; j++) {
//pressed button is containing an item
if (i == j)
{
//Set sprite to show the item icon THIS WORKS FINE
itemSlot[1].sprite = inventory[j].itemIcon;
//Add the listener(this works until i actually click the button) than throws argument out of range error which is weird since setting the sprite works just fine.
itemButton.onClick.AddListener(delegate { checkItemClicked(inventory[j]); });
Color color= itemSlot[1].color;
color.a = 1.0f;
itemSlot[1].color = color;
}
}
Im pretty new to Unity so I have no idea how to fix these.
Follow this Question
Related Questions
Button position scaling weird 1 Answer
UI button in Panel not clickable 2 Answers
Delay Button Pressed Action after Animation 1 Answer
Button only works once 1 Answer