HELP! Block placing and destroying script doesn't work properly!

Started by
-1 comments, last by Kiel368 11 years, 5 months ago
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)
{
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;
}
}
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.
Please help, this is very important to me!

This topic is closed to new replies.

Advertisement