Hello I am making a game like minecraft in unity and I am having a problem with placing blocks
when the player places a block it places but if you continue placing in the same spot the block will go inside of the other block. How do I fix that?
here is the code I am using:
var range : float = Mathf.Infinity;
var hit : RaycastHit;
var Box : GameObject;
function Update()
{
if(Input.GetMouseButtonDown(1)){
Build();
}
}
function Build()
{
if(HitBlock()){
var Box = Instantiate(Box);
Box.transform.position = hit.transform.position + hit.normal;
}
}
function HitBlock() : boolean
{
return Physics.Raycast(transform.position, transform.forward, hit, range);
}