[help req] spawning voxel terrian with noise C#

hello i have a problem using the noise method. i want to use it to genrate a y max hight.

int chunkSize = 16;
public static int[,] map;

// some were in the code i define the map value

map = new int[chunkSize,chunkSize,chunkSize]

void CallculateMap() {

if (transform.position.y < 64)
{
for (int x = 0; x < chunkSize; x++)
{
for (int z = 0; z < chunkSize; z++)
{
float pNoise = Mathf.PerlinNoise(transform.position.x, transform.position.y);

for (int y = 0; y < chunkSize; y++)
{
if(pNoise < 1)
map[x,y,z] = 1;
}

}
}
}

}

I would direct you to the help page for that perlin noise function:

It has a pretty good example of how to use it, but overall, your main problem is that you get your float on the z for loop, meaning that each of your y that have the same z coordinate will have the exact same “noise” value for your IF.

A second problem is that you are not making use of x and z from the iterration, meaning that as long as the transform.position doesn’t change, you should get the same value.

My “solution” is not tested, and probably not good for your solution, as it doesn’t locate the “chunk” coordinates and such, so all your chunks would end up similar, but it should help a bit:

    for (int x = 0; x < chunkSize; x++)
    {
        for (int z = 0; z < chunkSize; z++)
        {
            for (int y = 0; y < chunkSize; y++)
            {
                float pNoise = Mathf.PerlinNoise(x, y);
              
                //Do whatever with your noise
            }
        }
    }

EDIT:
Personally, I might have used a random instead, but that’s because I come from a place where the perlin noise is not an implemented function, and you have to make one yourself or use other tools.