Question by
alexandrunicolae99 · Dec 03, 2019 at 02:31 AM ·
gameobjectinstantiatelist
Changing GameObject values from a list
I have a list of gameobjects with a script attached to them, i Instantiate them and then add each of them to a list with this:
private void InstantiateSlot()
{
for(int y = Y1; y >= Y2; y += YIncrement)
{
for (int x = X1; x <= X2; x += XIncrement)
{
Slots.Add(Instantiate(Slot, Inventory.transform, false).gameObject);
Slots[Slots.Count-1].transform.localPosition = new Vector3(x, y, 0);
}
}
}`
To make sure things work properly, i have written these 3 lines as a test, but for some reason, in the inspector the item does not have its value changes but the debug log shows the correct item(basically the element of the list changed the value, but the element from the scene does not)
Slots[0].GetComponent<Slot>().SlotItem = TestItem;
Slots[0].GetComponent<Slot>().UpdateSlotSprite();
Debug.Log(Slots[0].GetComponent<Slot>().SlotItem);
The question is how can i store multiple instantiated objects in a list and be able to change their values from the list itself(like in the example above)
Comment