Hello guys! I’m a bit confused at the moment, since I’m keep getting Null reference errors while referring to a 2D array from Script1 to Script2. I read some threads connected to this topic but they don’t seem to provide an exact answer.
How do my scripts look?
Script 1:
public int[,] landArrayLive;
public int rowmax;
public int colmax;
void Awake()
{
landArrayAlive = new int[rowmax, colmax]
}
void Start()
{
for (currx = 0; currx < rowMax; currx++) {
for (currz = 0; currz < columnMax; currz++) {
landArrayAlive [currx, currz] = 0;
landArray[currx,currz] = 0;
}
}
Then in Script 2:
public int landArrx;
public int landArrz;
public GameObject landOrg;
public LandScript landScript;
public int[,] landArrB;
void Start ()
{
landArrx = 1;
landArrz = 1;
landOrg = GameObject.FindGameObjectWithTag ("LandOrganizer");
landScript = landOrg.GetComponent<LandScript>();
landArrB = landScript.landArrayAlive;
}
void Update()
{
landArrB [landArrx, landArrz] = 1;
}
And this gives me a Null exception error, pointing to the line where “landArrB [landArrx, landArrz] = 1;” is. Do 2D arrays have special rules when referring to them?
UPDATE
By changing the initialization of landArrayAlive to Awake, I now face the IndexOutOfRange error…which is weird since 1 is clearly less than 10…any ideas?