I cant reference Objects in an array. Int array works

Hello,
i made an array and tried to make the array full of public game objects (Panel1,Panel2,…). But i cant include the Panel in the array. I can call the object in every other function but not in the array. An int array (ints) works perectly. I think a verry simple misstake.
Thank you for your help

public GameObject Panel1;public GameObject Panel2;public GameObject Panel3;public GameObject Panel4;
	public GameObject[] Panels = new GameObject[]{Panel1,Panel2,Panel3,Panel4};
	public int[] ints = new int[]{ 1, 2, 3, 4, 5 };

Looks like you can’t do “new GameObject{Panel1,Panel2,Panel3,Panel4};” in an initializer. Do it in a method instead.,Don’t know for sure, but you probably can’t do that in an initializer. So move “Panels = new GameObject{Panel1,Panel2,Panel3,Panel4};” to a Start or other script. In fact, if you are using Visual Studio, roll over “Panel1” with the red squiggle under, it will tell you can’t do that and why.

Try just doing:

public GameObject[] Panels;

and then assign your panels in the inspector.

Or you could call this part of your code in the start function instead

void Start(){
    public GameObject[] Panels = new GameObject[]{Panel1,Panel2,Panel3,Panel4};
}