Building with various LEGO Bricks?

Hello, I was wondering if there was a way to make something that allows you to build with lego bricks in unity by instantiating. But when you instantiate, the bricks stay the correct distance apart from each other so that the bricks don’t go through each other. I have tried before but when I lay down a brick, and then another, it just goes through the exsiting brick. And when I try adding multiple bricks to the game. They just spawn wherever the mouse position is and they don’t snap to the correct height and distance. If anyone could help. I would be thankful! Here is my current script for 2 bricks :

var Brick1 : Transform;
var Brick2 : Transform;

var Brick1Selected : boolean = false;
var Bick2Selected : boolean = false;

function Update(){
if(Input.GetKeyUp(KeyCode.P)){
Brick1Selected = true;
Brick2Selected = false;
}
if(Input.GetKeyUp(KeyCode.O)){
Brick2Selected = true;
Brick1Selected = false;
}
if(Input.GetMouseButtonUp(1)){
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if(Physics.Raycast(ray,hit,100) && hit.transform.tag == "Brick"){
if(Input.GetMouseButtonDown(1)){
if(Brick1Selected){
var NewBrick : Transform = Instantiate(Brick1,hit.collider.transform.position, Quaternion.identity);
}
if(Brick2Selected){
var NewBrick2 : Transform = Instantiate(Brick2,hit.collider.transform.position, Quaternion.identity);
}
}
}
}
}

From the look of it you are telling Instantiate that you want a copy of Brick[1/2] in the exact location of the object that you clicked on. For instance,

var NewBrick : Transform = Instantiate(Brick1,hit.collider.transform.position,
    Quaternion.identity);

This is saying “Get me a copy of Brick1, and put it on the exact position of the object that the raycast hit.” I would modify hit.collider.transform.position so that it is different. The logic will be up to how exactly you want it to work, but for testing you can try hardcoding a new position just to make sure that everything is working and the position itself is wrong.

Hope this helps in some way!