- Home /
This script does not work propely in my game
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);
}
Comment
Answer by ScroodgeM · Jul 30, 2012 at 09:37 PM
99% sure that you forgot to create a collider for 'Box' - colliders needs for raycast
Your answer
Follow this Question
Related Questions
Realistic block placing/building 1 Answer
A node in a childnode? 1 Answer
[Script] place block(prefab) align to grid like minecraft? 4 Answers
How do I control the block placing? 1 Answer
How can i fix this Compiler Error? 0 Answers