- Home /
Minecraft-like block placement/deletion help
I currently have a script that uses ray-casting to find where to place/delete the block but, when I delete a block it sometimes deletes my player and when I place a block either it places the block on my player's "head" or it places a block not in the place where my cursor is (The cursor is locked to the middle of the screen). I though I found a way to fix this by setting the player to "Ignore Ray-cast" but, when i do that, it wont place or delete a block! Also, I coded it so that the block place according to a grid. Is there a way to place blocks like in Minecraft without using Raycast? If so, could you explain how?
Thanks!
Answer by Driseus · Jun 08, 2012 at 02:36 PM
Yes, you could create a cube and attack a script to it with a void OnMouseOver and a void OnMouseExit, then you just create a script with a public static bool[] cubeHovers= new bool[number of cubes in your grid]; in it. On your mouseover/mouseexit script you add these lines.
void OnMouseOver(){
ExampleSctipt.cubeHovers[numberOfthisCube]=true;
}
void OnMouseExit(){
ExampleSctipt.cubeHovers[numberOfthisCube]=false;
}
in your ExampleScript with the boolean you now add a public Transform[] cubeGrid= new Transform[number of Cubes];
and in void Update(){
for(i=0;i
bool thisBool=cubeHovers[i];
if(thisBool==true&&Input.GetButtonDown("Fire1")){
Instantiate(any Transform, cubeGrid[i].position,Quaternion.identity);
}
}
i know that you have to change some things but i hope the idea is usefull for you