I’m working on an inventory system, and I am very close to being able to click an active slot, destroy the object already there, and then place the new object. The thing is, I am using scriptable objects to make the inventory system because I want a system that I can just make a scriptable object and then it works without any other input needed. I can’t seem to get the active GameObject to link up with the variable on the scriptable object so then I can get the GameObject on the scriptable object that the image is sitting on. I’m sorry if you don’t understand, but its hard to explain. I have the code to look at though on the bottom. I basically go through a loop looking for if the image is the same as the S.O. with the variable of i for the duration of the amount of items(scriptable objects) I have. The main part I need help with is the if statement in the for loop. If you could help that would be great. Thanks!
public void EquipItem(Button clicked)
{
if (clicked.gameObject.transform.childCount == 1)
{
Destroy(currentOBJ);
for (int i = 0; i < items.Length; i++)
{
if (GameObject.ReferenceEquals(items*.itemSprite, clicked.transform.GetChild(0)))*
{
currentOBJ = Instantiate(items*.itemObj, hand.transform.position, hand.transform.rotation);*
currentOBJ.transform.parent = hand.transform;
break;
}
}
}
else
{
Debug.LogError(“No child”);
}
}