My first script makes an array and fills it with objects:
IEnumerator CreateTerrain ()
{
for (int px=0; px<chunkSize; px++)
{
for (int pz=0; pz<chunkSize; pz++)
{
float Perlin1 = Mathf.PerlinNoise((px+ transform.position.x) /xScale, heightScale);
float Perlin2 = Mathf.PerlinNoise((pz+ transform.position.z) /xScale, heightScale);
int x = (int) Mathf.FloorToInt(px + transform.position.x);
int height = (int) Mathf.FloorToInt(Perlin1*40*Perlin2);
int z = (int) Mathf.FloorToInt(pz + transform.position.z);
for (int y=0; y<height; y++)
{
yield return new WaitForSeconds (1/blocksPerSecond);
GameObject currentBlock = GameObject.Instantiate(blocks[0], new Vector3(x, y, z), Quaternion.identity) as GameObject;
currentBlock.transform.parent = transform;
levelData[x, y, z] = currentBlock;
}
}
}
foreach (Transform block in transform)
{
block.GetComponent<BlockScript>().UpdateSides();
}
}
My Script that im getting the error on is:
public void UpdateSides ()
{
levelData = new GameObject[chunkSize, chunkHeight, chunkSize];
levelData = leveldataScript.levelData; *** null reference exception ***
print (levelData.GetLength(0) + " , " + levelData.GetLength(1) + " , " + levelData.GetLength(2));
int x = (int) transform.position.x;
int y = (int) transform.position.y;
int z = (int) transform.position.z;
// it continues.....
iv been trying to figure out why im getting the error but i have no idea. The console prints out: 10, 100, 10 which means that the array isnt null. Can anyone help please thank you