make grid of gameobjects between 2 points

I have been trying to do this for a few hours in unity now but cant get my head around it. basically i have 4 points(vector3) 1 each for the 4 corners topleft, topright, bottomleft, bottomright. now i have a sprite that i use as a block what i want to do is basically fit X number of blocks within the four points. see the image below. I cant think of a way to do this right now. i would appreciate any Ideas on how to do this.

Hi,
What part are you struggling with?
You will need to instantiate 5 rows of 5 sprites - to do so you use something like this

        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 5; j++)
            {
            //here you put your code to instantiate 1 sprite
            //then you use i and various items to set your Y position 
            //and j to set the X position
            }

You will need to calculate your distance between top left and top right and between top left and bottom left and divide that by 5 then use that to scale your sprite and also to move in on x or y (multiplying it by i or j) depending… you may also need to add an additional half of that 5th if you want it to start with the top left corner in the top left of your first sprite.

Below is some code I used to generate a grid - it may help

function GenerateGrid ()
{
generateGrid = false;
for(var i : int = -halfWidthX; i <halfWidthX; i++)
	{
	for(var z : int = -halfHeightZ; z <halfHeightZ; z++)
		{
		var tempTile = Instantiate(tile,Vector3(startPos.x+i,startPos.y,startPos.z+z),Quaternion.identity);
		tempTile.transform.name = "Tile";
		tempTile.transform.parent = gridHolder;
		}
	}
}

hope that helps,

Wanted to make sure this works 100%, so I did a test run.

The Setup: If you want it to line up, offset the mesh/sprite object inside a parent game object by half so that the transform of the parent sits at the bottom left corner of the object. Notice where the transform is in the image

The Result:
67557-spritegridc.jpg

using UnityEngine;
using System.Collections;

public class ResizeGrid : MonoBehaviour {


    public Transform pointA;
    public Transform pointB;
    public Transform pointC;
    public GameObject spritePfb;

    public int gridWidth = 5;
    public int gridHeight = 5;

    void Start()
    {
        GenerateGrid(pointA.position, pointB.position, pointC.position);
    }


    void GenerateGrid(Vector3 a, Vector3 b, Vector3 c)
    {
        GameObject container = new GameObject();
        container.name = "Grid Container";
        container.transform.position = c;
        float spriteWidth = Vector3.Distance(a, b) / gridWidth;
        float spriteHeight = Vector3.Distance(a, c) / gridHeight;

        for (int x = 0; x < gridWidth; x++)
        {
            for (int y = 0; y < gridHeight; y++)
            {
                GameObject sprite = (GameObject)Instantiate(spritePfb, container.transform.position, Quaternion.identity);
                sprite.transform.parent = container.transform;
                sprite.transform.localPosition = new Vector3(x * spriteWidth, y * spriteHeight, 0);
                sprite.transform.localScale = new Vector3(spriteWidth, spriteHeight, 1);
                
            }
        }
    }
}