How can I fix this?

I am using a grid in a 3D project so I changed the grid to XZY and the tilemap to XZ so the tiles would be horizontal instead of vertical and I wrote this script that should tell me the tile sprite:

public class From2DTo3D : MonoBehaviour
{
    int rows = 100;
    int cols = 100;
    public Tilemap tilemap;
    // Start is called before the first frame update
    void Start()
    {
        Make3DMap();
    }
    // Update is called once per frame
    void Update()
    {
      
    }
    void Make3DMap()
    {
        for(int x = -100; x < rows; x++)
        {
            for(int z = -100; z < cols; z++)
            {
                if(tilemap.GetSprite(new Vector3Int(x, 0 , z)) != null)
                {
                    Sprite sprite = tilemap.GetSprite(new Vector3Int(x , 0 , z));
                    print(x+ " , " + z + " " + sprite.name);
                }
                else if(tilemap.GetSprite(new Vector3Int(x, 0, z)) == null)
                {
                   // print(x + " , " + z + " null");
                }
            }
        }
    }

The problem is it only tells the sprites of tiles with 0 in the Z axis and I don’t understand why…

Hello, try to uncomment the line

// print(x + " , " + z + " null");

Maybe you only created tiles with z = 0 ? You should also show us of you do fill your tiles.

Also, there is something strange in your code. You state that number of row and col is 100.
But in you for loop you actually go from -100 to 100 (that is 200 tiles).

for(int x = -100; x < rows; x++)
{
    for(int z = -100; z < cols; z++)
    {
      
    }
}

//It probably should be :

for(int x = 0; x < rows; x++)
{
    for(int z = 0; z < cols; z++)
    {
      
    }
}

I tried the print null code you mentioned it just says that everything that isn’t at z = 0 is null. I started at -100 because I wanted 200 tiles that start from -100, -100 to 100, 100.
This is the grid as you can see it has tiles from -100 -100 to 100 100 (I left some null to check if they would be called null) I made sure that I filled all the tiles using the line.

Please don’t make duplicate posts: Why is this happening?

Thanks.