when i run this code i get the message “Transform child out of bounds”. how do i fix that?
public class Inventory : MonoBehaviour
{
private bool inventoryEnabled;
public GameObject inventory;
private int allSlots;
private int enabledSlots;
private GameObject[] slots;
public GameObject inventorySlots;
private void Start()
{
allSlots = 35;
slots = new GameObject[allSlots];
for(int i =0; i < allSlots; i++)
{
slots[i] = inventorySlots.transform.GetChild(i).gameObject;
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.I))
{
inventoryEnabled = !inventoryEnabled;
}
if (inventoryEnabled == true)
{
inventory.SetActive(true);
}
else
{
inventory.SetActive(false);
}
}
}