private void CreateChunk(int x, int y, int z) { CubeGrid chunk = Instantiate(cubeGridPrefab) as CubeGrid; chunk.Initialize(resolution, chunkSize, isoLevel, interpolation, x, y, z, heightMap, noiseWeight); chunk.transform.parent = transform; chunk.transform.localPosition = new Vector3(x * chunkSize, y * chunkSize, z * chunkSize); if (x > 0) { chunks[x - 1, y, z].xNeighbor = chunk; } if (y > 0) { chunks[x, y - 1, z].yNeighbor = chunk; } if (z > 0) { chunks[x, y, z - 1].zNeighbor = chunk; } if (x > 0 && z > 0) { chunks[x - 1, y, z - 1].xzNeighbor = chunk; } if (x > 0 && y > 0) { chunks[x - 1, y - 1, z].xyNeighbor = chunk; } if (z > 0 && y > 0) { chunks[x, y - 1, z - 1].zyNeighbor = chunk; } if (x > 0 && y > 0 && z > 0) { chunks[x - 1, y - 1, z - 1].xyzNeighbor = chunk; } chunks[x, y, z] = chunk; }