How can I get cubes to spawn on the edge of another cube? (I'll go in depth in description)

So I am trying to create a little voxel editor. The player will be able to place a base cube, and then place other cubes on the base cube’s edges. Here is a screenshot of what I have so far: Imgur: The magic of the Internet

The way I’m doing this is by using a raycast, finding the point where it hits the base cube, and then placing the new cube there. In the screenshot you can see that there is a “target cube” that shows where the next cube will be placed.

The issue I ran into is that because the point where the raycast hits the base cube is right on the surface of the cube, the child cubes are placed right there and consequently end up half inside the base cube. I don’t want the cubes to be placed in such a way where they are overlapping with the base cube, I want the new cubes to be completely outside the base cube so they are sitting on the edge. I want it like this so that I can attach all the rigid bodies without any issues. I just can’t really think of a way to do this.

The only way I can think of solving this would be to check which side the target cube (or target position) is on, relative to the base cube, and move the new cubes accordingly. So if the target cube was on the left side of the base cube is would move the target cube left by 0.5 in order to account for it being half inside the base cube.

Does anyone have any other ideas? Any help is appreciated:)

I did something like this; with snap points etc…
However, I ran into this problem. My fix was making the target block always in front of me, that way, I can get any snap point I want.

https://gyazo.com/ebcc6a756f0420c1e38eb0ff1ac8822b

I tried to do what you are doing but it didn’t seem to work.

What do you mean by snap points?

I finally fixed it!! If anyone is interested, here is the code

if (objectHit.point.z <= objectHit.transform.position.z - (targCbScl.z/2))
   //back
   targetCube.transform.position += new Vector3(0, 0, -(targetCube.transform.localScale.x / 2));
else if (objectHit.point.z >= objectHit.transform.position.z + (targCbScl.z / 2))
   //front
   targetCube.transform.position += new Vector3(0, 0, (targetCube.transform.localScale.x / 2));
else if (objectHit.point.x <= objectHit.transform.position.x - (targCbScl.x / 2) )
   //left
   targetCube.transform.position += new Vector3(-(targetCube.transform.localScale.x / 2), 0, 0);
else if (objectHit.point.x >= objectHit.transform.position.x + (targCbScl.x / 2))
   //right
    targetCube.transform.position += new Vector3((targetCube.transform.localScale.x / 2), 0, 0);
else if (objectHit.point.y <= objectHit.transform.position.y - (targCbScl.y / 2))
   //top
   targetCube.transform.position += new Vector3(0, -(targetCube.transform.localScale.x / 2), 0);
else if (objectHit.point.y >= objectHit.transform.position.y + (targCbScl.y / 2))
   //bottom
   targetCube.transform.position += new Vector3(0, (targetCube.transform.localScale.x / 2), 0);