I need to declare an Array of Lists variable in Unity. Array size is fixed and it is 5. My code is working as i want, but i think there must be a better and a shorter way to do it:
public List<GameObject>[] charactersOnBoardSortedP1 = new List<GameObject>[] {new List<GameObject>(), new List<GameObject>(), new List<GameObject>(), new List<GameObject>(), new List<GameObject>() };
I tried to do like this:
public List<GameObject>[] charactersOnBoardSortedP1 = new List<GameObject>[5];
But i have an error: Object reference not set to an instance of an object.
Is there any way to declare my variable simpler? I mean if my array has only 5 slots it's ok, but what if 100? It's kind of stupid to copy new List... 100 times in declaration.