Assigning a GameObject variable to equal another GameObject variable via C# script.
Hey,
So I made a simple inventory system that has been working fine for quite a while now. It is only after I messed with it a little (basically just less inventory slots) that it broke. Everything else is still the same and yet one part is not working.
public GameObject[] inventorySlots = new GameObject[34];
public GameObject[] characterSlots = new GameObject[8];
public GameObject currentSelection;
public GameObject tempItemHolder;
public GameObject emptySlot;
void Start() {
currentSelection = emptySlot;
tempItemHolder = emptySlot;
}
public void slot0() {
Debug.Log("PRESSED");
tempItemHolder = inventorySlots[0];
inventorySlots[0] = currentSelection;
currentSelection = tempItemHolder;
}
The inventorySlots[0] has a placeholder item in it. The emptySlot has an "Empty Slot" prefab in it. The button is working fine as when I click it I do get a "PRESSED" debug notification.
Only the problem is is that it doesn't seem to be doing anything. I can see the variables from the inspector while playing and none them change at all. It is weird because it was working fine before I lowered the number of slots (used to be 55 instead of 34).
If anyone can see the problem or needs more information please let me know. Apologies for any formatting problems. Thanks!
I assume you assign items to inventorySlots via Editor drag & drop? Can you check that your placeholder item is still there after you updated the count?
Strange, I don't see why that would be the case. When dealing with issues like this, and when you know that it worked before, the general recommendation is to revert to that past state and confirm that it is still working.. Then try to apply your new changes step by step again to see where it breaks. Also, can you please post the screenshot of your inspector window with these variables?