i would like to do a 3D array of a class rather than an integer. what i’d like to have is something like:
public CellData[,,] constellationInstance = new CellData[8,8,8];
public class CellData
{
//define a Game Object to be associated with at Start
public GameObject cellObject;
//is the cell enabled? (true/false)
public bool cellEnabled=false;
//define an Intensity value (same value for all rows at a position)
public int cellIntensity;
}
but it seems the issue is that i can’t seem to set values because nothing’s been initialized in advance. checking the manual assignment examples on MSs site doesn’t seem to be helpful. using for loops seems like the way to go like so:
for (int i = 0; i < 8; ++i)
for (int j = 0; j < 8; ++j)
for (int k = 0; k < 8; ++k){
constellationInstance[k,j,i].cellEnabled=false;
if(constellationInstance[k,j,i].cellIntensity == null)
constellationInstance[k,j,i].cellIntensity=100;
if(constellationInstance[k,j,i].cellObject == null)
{
GameObject cellObj = GameObject.Find("Constellation/Layer_"+k+"/Row_"+rowNames[j]+"/pos"+i);
cellObj = cellObj.transform.GetChild(0).transform.gameObject;
constellationInstance[k,j,i].cellObject = cellObj;
}
}
running this i get an immediate NullRef, assumedly because i did not initialize the value properly. any clue how i can properly initialize this data?