# Repeated objects, and sprite layering

In my game I have a script, that creates a bounded area from wall block prefabs.

``````private void CreateWalls()
{
// calculate the center position of the area, add offset
Vector3 centerPos = new Vector3((xSize / 2f - 0.5f) - xOffset, (ySize / 2f - 0.5f) - yOffset, 0f);

// create the walls on the x axis
for (int x = 0; x < xSize; x++)
{
Instantiate(wallPrefab, new Vector3(x - centerPos.x, -centerPos.y, 0), Quaternion.identity, transform);
Instantiate(wallPrefab, new Vector3(x - centerPos.x, ySize - 1 - centerPos.y, 0), Quaternion.identity, transform);
}

// create the walls on the y axis
for (int y = 0; y < ySize; y++)
{
Instantiate(wallPrefab, new Vector3(-centerPos.x, y - centerPos.y, 0), Quaternion.identity, transform);
Instantiate(wallPrefab, new Vector3(xSize - 1 - centerPos.x, y - centerPos.y, 0), Quaternion.identity, transform);
}
}
``````

My sprites are a bit taller then the actual blocks, however the instantiated blocks on the y axis have the sprites layering on top of each other the wrong way around. How could I fix this? My initial thought was that maybe I could have each object on the y axis be somehow set to have their order on layer increased by 1, but I also wonder if there’s a more straightforward way of doing this using unity’s sprite functionalities?

I believe order in layer would be the normal way of doing this.