I have a grid floor which will perfectly spawn objects on the x and z coordinates if the scale of object is 1, how do I spawn objects in a grid space if its larger than 1 scale?

Spawning an object that is scaled 1 by 1: 134304-unity-2019-03-06-16-50-16.png

Now when the object is bigger than 1 scale, example this 2 by 2 object:
134305-unity-2019-03-06-16-50-40.png

How do I correct the position so it won’t hang off the map, and keep the same vector positon?

Here is the building spawning code:

public class BuildingSpawner : MonoBehaviour
{

public Camera myCamera;

private Vector3 rawPos;


private GameObject parentForBuildings;

public GameObject spawnSelectedObject;
public Vector3 roundedPos;
public List<Vector3> gridTakenList;
public ObjectsData objectsData;
 
// Use this for initialization
void Start() {
    
   
    parentForBuildings = GameObject.Find("buildingsParent");
    if (!parentForBuildings) // if parentForBuildings doesn't exist, make it exist!
    {
        Debug.LogWarning("No parent for Buildings found! Creating one!");
        parentForBuildings = new GameObject("buildingsParent");
    }
}

// Update is called once per frame
void Update() {
    
}

void OnMouseDown() {
    
    spawnSelectedObject = ButtonManager.selectedBuilding; // Selected building from buttonManager.cs
    if (!spawnSelectedObject)
    {
        Debug.LogWarning("Need to select object in order to build!"); // Prevents null warning!
    }
    

    
    
    //rawPos is set using this method:
    mousePosRay();

    roundedPos = snapToGrid(rawPos); // Raw Pos get converted into a rounded Vector

    Debug.Log("Snap To Grid Vector: " + roundedPos);

    if (gridTakenList.Contains(roundedPos))  //click position has object in the same position
    {

        Debug.LogWarning("Spawn nothing since grid spot already has a building");
    }
    else if (spawnSelectedObject)
    {
        objectsData = spawnSelectedObject.GetComponent<ObjectsData>();
        objectsData.BuildingIdData("Blank", 100);

        Debug.LogWarning("Grid spot is open, placing building in position: ");
        buildingSpawner(roundedPos, spawnSelectedObject);
        gridTakenList.Add(roundedPos); // Keeps track if buildings already in a grid position
        

    }
}

#region Mouse Click Calculations
void mousePosRay() {
    RaycastHit hitInfo;
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    if (Physics.Raycast(ray, out hitInfo))
    {

        //Debug.Log("The hit point is:" + hitInfo.point);
        rawPos = hitInfo.point;
    }

}

Vector3 snapToGrid(Vector3 rawWorldPos) {
    float newX = Mathf.RoundToInt(rawWorldPos.x);
    float newY = Mathf.RoundToInt(rawWorldPos.y);
    float newZ = Mathf.RoundToInt(rawWorldPos.z);
    return new Vector3(newX, newY += 0.50f, newZ);

}
#endregion

void buildingSpawner(Vector3 pos, GameObject mainObjectTospawn) {
    if (!mainObjectTospawn) // Secound fail safe
    {
        return;
    }

    GameObject tempObject = Instantiate(mainObjectTospawn, pos, transform.rotation) as GameObject;
    tempObject.transform.parent = parentForBuildings.transform;
    

    
    
    
    
}

}