# Limit the grid fill

I'm doing some grid snapping and I wanted to fill out my grid on the gameObject surface. However I can't figure out the math on how to limit the grid fill. Here's the snippet:

private void Values()
{
sizePlace.y = baseGrid.transform.localScale.y / sizeGridX;
sizePlace.z = baseGrid.transform.localScale.z / sizeGridZ;
sizePlace.x = baseGrid.gameObject.GetComponent<MeshRenderer>().bounds.size.x*1.6f;

gridPosition.y = (baseGrid.transform.localScale.y / 2) - (sizePlace.y / 2);
gridPosition.z = (baseGrid.transform.localScale.z / 2) - (sizePlace.z / 2);
gridPosition.x = baseGrid.transform.position.x;

startGridPosition = gridPosition;
}


baseGrid is the gameObject surface and Place is basically a flat cube where I made it as a grid. The picture below illustrate my problem. No matter how many grids in the game, the grid will resize itself and they will always spawned exceeded the wall size. I'm not very good at math and stuff so if someone could guide me, I would be glad. Thanks thanks thanks!

UPDATE: Ok I managed to limit the fill but I don't know why they won't cover all the area of the wall. (( Here's the updated code:

sizePlace.y = baseGrid.gameObject.GetComponent<MeshRenderer>().bounds.size.y / sizeGridX;
sizePlace.z = baseGrid.gameObject.GetComponent<MeshRenderer>().bounds.size.y / sizeGridZ;
sizePlace.x = baseGrid.gameObject.GetComponent<MeshRenderer>().bounds.size.x*1.6f;

gridPosition.y = (baseGrid.gameObject.GetComponent<MeshRenderer>().bounds.size.y / 2) - (sizePlace.y / 2);
gridPosition.z = (baseGrid.gameObject.GetComponent<MeshRenderer>().bounds.size.z / 2) - (sizePlace.z / 2);
gridPosition.x = baseGrid.transform.position.x;

startGridPosition = gridPosition;


Ok what a silly mistake I did, my sizePlace.z is calculated using baseGrid bound.size.y instead of bound.size.z. Problem solved.
sizePlace.z = baseGrid.gameObject.GetComponent<MeshRenderer>().bounds.size.z / sizeGridZ;