I am making a simple inventory and im trying to make it not do anything if the array is empty, but when it looks to see if it is null it says that it cant check because it is null. How do I fix this?.
here’s part of the script
public GameObject[] Slots;
void OnGUI()
{
GUI.skin.font = font;
int offset = 0;
for (int x = 0; x <= 30; x++) {
if(Slots[x]!= null){
if (GUI.Button (new Rect (10 + offset, 140, 60, 60), Slots[1].name))
{
Debug.Log(x);
}
offset += 65;
}
}
here is the error
IndexOutOfRangeException: Array index is out of range.
ObjectHolder.OnGUI () (at Assets/Scripts/ObjectHolder.cs:37)