Procedurally Generate Field of Squares

I’m not sure at all how to go about this but what I want to do is generate a field of squares of random sizes but all fit within an allotted area (a larger square). The meshes generated are supposed to be planes but have to fit within a larger invisible plane, how can I go about doing this?

EDIT: Is there a way I can hold an array of arrays of Vector2’s (the arrays of Vector2’s would hold the four vertices of the squares, and the larger one all of the squares, that way I can check what positions for new vertices are available and which aren’t)?

Why not use an Integer or Vector2 for the size of the larger square and add the random X and Y size to each number. For example:

int large_size_x = 0; //Lets say your large grid is 30 in size
int large_size_y = 0;

if (large_size_x < 30 && large_size_y < 30)
{
    var xNum = Random.Range(1, 20); //Size of the actual grid
    var chosenx = xNum; //Add the size of your smaller grid to the large overall variable.
    
    //Spawn your grid here and use local transform to edit the size
    var small_grid = Instantiate (gridObject, transform.position, Quaternion.identity);
    large_size_x += chosenx;
    small_grid.transform.position.x += chosenx;
}

Not Tested

Hope this gives you some grounds to go off :slight_smile: