Problem at Minecraft like game

I am programming a game like Minecraft.
My problem is that I cant place blocks how i want it.


Here you can see that I am ponting on a block and want to place another block infront of it.
The red line in the Scene view is the line were I am pointing at and the blue line is the line were the game wants to place the block.

My script for this is:

using UnityEngine;
using System.Collections;

public class PlaceBlock2 : MonoBehaviour {

	public float range = 5; 
	public Transform prefab;
	RaycastHit hit;	
	// Use this for initialization
	void Start () {	
	// Update is called once per frame
	void Update () {
		Ray ray = Camera.main.ScreenPointToRay (new Vector3(Screen.width*0.5f, Screen.height*0.5f, 0f));

		if (Physics.Raycast(ray, out hit,range)){
			// Pointing Ray

			// Point to place
			Vector3 V = new Vector3(Mathf.Round(hit.point.x), Mathf.Round(hit.point.y+0.5f), Mathf.Round(hit.point.z));

			// Place Ray

			// Place Block
				Instantiate(prefab,V,  Quaternion.identity);


Is my point to place wrong or were is my error.

You could try using Mathf.Floor, or determine a point that is slightly inside the cube you are hitting by taking the hit.point and adding the camera’s transform.forward * 0.01f to it, and then rounding this point instead.
Besides that, take a look at the After playing Minecraft… thread, there are more sultions to your problem included.

You need 2 booleans to see which way to round to for the mine craft placement system.

bool XPositive = hit.point.y > hit.transform.position.y ? true : false;
bool XNegative = hit.point.x > hit.transform.position.x ? true : false;

If you need more help, just ask and I’ll explain further.

that kinda worked , but the blocks still place inside each other. plus they dont always work still.
maybe try adding a line that says if a block in a piece of the grid is 1 then dont place there.