- Home /
HELP! Block placing and destroying script doesn't work properly.
Hi everyone! I've got a problem. I have voxel game written in Unity. I've got a script attached to my main camera to destroy and place blocks. It works like this:
for (float x = 0; x < 5f; x += 0.05f)
It works fine but when i have a selector (GUITexture in the middle of the screen) it doesn't fit perfectly. Functions GetPlayerPosChunkOffset2D, GetRelativeBlockPos, BlockAtPoint and SetBlock are written properly.
{
Vector3 targetPoint = transform.position + (transform.forward * x);
BlockType blockType = ((World)world.GetComponent(typeof(World))).BlockAtPoint(targetPoint);
if (blockType != BlockType.Air)
{
if (targetPoint.y > 2)
{
Vector2 targetChunkOffset2D = PlayerUtils.GetPlayerPosChunkOffset2D(targetPoint);
Vector3 targetChunkOffset3D = new Vector3(targetChunkOffset2D.x, 0, targetChunkOffset2D.y);
Vector2 targetBlockOffset2D = PlayerUtils.GetRelativeBlockPos(targetChunkOffset3D, targetPoint);
Vector3 targetBlockOffset3D = new Vector3(targetBlockOffset2D.x, targetPoint.y, targetBlockOffset2D.y);
((World)world.GetComponent(typeof(World))).SetBlock(targetChunkOffset3D, targetBlockOffset3D, BlockType.Air);
}
break;
}
}
Please help, this is very important to me!
Your answer
Follow this Question
Related Questions
Disabling a GameObject via keyboard 2 Answers
[Closed] MainMenu Script error 2 Answers
Level Button And Quit Button Android 2 Answers