Generating Chunks

Hello, so i have finaly managed to generate chunks with a lot of help from this great community. So i want to generate only visible block for now, but i am stucked at there how to manage thath, i have now only chunks and 1 block generated, here is my code:

ChunkData.cs

public class ChunkData
{
    private int x, y, z;

    public ChunkData(int _x, int _y, int _z)
    {
        x = _x;
        y = _y;
        z = _z;
    }

    public int X
    {
        get { return x; }
        set { x = value; }
    }

    public int Y
    {
        get { return y; }
        set { y = value; }
    }

    public int Z
    {
        get { return z; }
    }

    public override string ToString()
    {
        return string.Format("Chunk ( {0},{1},{2} )", x, y, z);
    }
}

WorldData.cs

public class WorldData
{
    private int chunkWidth = 32, chunkHeight = 128, chunkDepth = 32;
    private int chunksX = 8, chunksY = 1, chunksZ = 1;

    public ChunkData[, ,] chunks;

    public const int BottomChunkBorderRow = 0, LeftChunkBorderColumn = 0;

    public void InitChunkGrid()
    {
        chunks = new ChunkData[chunksX, chunksY, chunksZ];

        for (int x = LeftChunkBorderColumn; x <= RightChunkBorderColumn; x++)
        {
            for (int y = BottomChunkBorderRow; y <= TopChunkBorderRow; y++)
            {
                for (int z = 0; z < chunksZ; z++)
                {
                    chunks[x, y, z] = new ChunkData(x, y, z);
                }
            }
        }
    }

    public int ChunkWidth
    {
        get { return chunkWidth; }
        set { chunkWidth = value; }
    }

    public int ChunkHeight
    {
        get { return chunkHeight; }
        set { chunkHeight = value; }
    }

    public int ChunkDepth
    {
        get { return chunkDepth; }
        set { chunkDepth = value; }
    }

    public int ChunksX
    {
        get { return chunksX; }
        set { chunksX = value; }
    }

    public int ChunksY
    {
        get { return chunksY; }
        set { chunksY = value; }
    }

    public int ChunksZ
    {
        get { return chunksZ; }
        set { chunksZ = value; }
    }

    public int TopChunkBorderRow
    {
        get { return chunksY - 1; }
    }

    public int RightChunkBorderColumn
    {
        get { return chunksX - 1; }
    }
}

WorldGameObject.cs

public class WorldGameObject : MonoBehaviour 
{
    private WorldData world = new WorldData();

    public Transform chunkPrefab;
    public Transform[, ,] chunkGO;

    void Start()
    {
        world.InitChunkGrid();

        CreateChunks();
    }

    private void CreateChunks()
    {
        chunkGO = new Transform[world.ChunksX, world.ChunksY, world.ChunksZ];

        for (int x = 0; x < world.ChunksX; x++)
        {
            for (int y = 0; y < world.ChunksY; y++)
            {
                for (int z = 0; z < world.ChunksZ; z++)
                {
                    ChunkData curChunk = world.chunks[x, y, z];

                    Vector3 chunkInstPos = new Vector3(curChunk.X * world.ChunkWidth, 0, curChunk.Y * world.ChunkHeight);

                    Transform chunkInst = Instantiate(chunkPrefab, chunkInstPos, Quaternion.identity) as Transform;

                    chunkInst.parent = transform;

                    chunkInst.name = curChunk.ToString();

                    chunkGO[x, y, z] = chunkInst;
                }
            }
        }
    }
}

So i have created new empty game object called World Spawn and attached WorldGameObject to it, and attached Grass prefab (Cube with grass texture). Now it generates only 1 block in chunk. So my question is how i can generate more blocks in these chunks and if possible thath i generate only visible blocks.

It doesn’t matter about the code, but it depends on the prefab.

  1. Go to your Prefab
  2. Edit whatever you want in the scale section