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);
}
}
}
}
}