Instantiated a cube next to another.

I am trying to build a game where you can attach prefabs together kind of like minecraft.
I have tried the raycast.hit and am stuck on the mathf to make the cubes not suck into each other, should I go that way? or should I use a joint kind of system.
I need to have different shapes and sides.
I was thinking of taking the cube and separating the 6 faces and putting a bool on the face you can put another cube.
If you have any other ideas I would appreciate anything.

For a shape as simple as a cube, you don’t need to go down to the mesh. Have the position, the size, and you can figure out the rest. If the size is unknown, use renderer.bounds or collider.size.

Now that you know what you’re dealing with, I suppose you press a button and a cube is created where you’re looking. Cast a ray.
If you hit the ground, you don’t have to care what is around, just create a cube on that spot of the grid => for instance, round the ray’s impact position to int.
If you hit a cube, find on which side you clicked (if ray’s impact pos.y > cube.pos.y + cube’s height, it’s on the top, etc) and create the cube there, with the correct offset.

using UnityEngine;
using System.Collections;

public class ConstructionSpacestation : MonoBehaviour
{
    public GameObject Builder;

    // placeholder for what you see on the screen.

    private Transform actualBlock;


    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 2000))
            {
                float dot = Vector3.Dot(transform.up, hit.normal);
                if (dot > 1)
                {
                    Debug.Log("yes");
                }

                // it's better to find the center of the face like this:
                Vector3 position = hit.transform.position + hit.normal;
                // calculate the rotation to create the object aligned with the face normal:
                Quaternion rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
                // create the object at the face center, and perpendicular to it:
                GameObject Placement = Instantiate(Builder, position, rotation) as GameObject;
                Debug.Log(hit.collider.gameObject.name);
            }
            else
            {
                //Debug.Log(hit.collider.gameObject.name);
            }
        }
    }
}