- Home /
Help with arrays, multidimensional
Hey guys,
I'm having a real issue grasping the concept of this so I hope I explain it well. I have searched though other answers on here and tried to implement an array in a container class instead of using a traditional 2D array for my tile manager.
I'm pretty much tearing my hair out trying to get it working, this is what I have;
[System.Serializable]
public class Rows
{
public int[] cols;
};
public class ArrayTest : MonoBehaviour {
public Rows[] rows;
void Start()
{
rows = new Rows[3];
rows[1].cols[1] = 100;
}
}
I've tried using a for loop to fill the elements, I've tried foreach. Everytime I get a NullReferenceException because while it initialised my 3 rows it never add anything to the cols.
Any help would be greatly appreciated.
EDIT: For clarification I want this to work in edit mode so I can size up, click and button and it'll build me a tile grid. I have this working with a 2D array but I can't seem to initialise the cols aspect of this in edit mode.