Add object to another object's selected face

Hello, I've been strugling for the past few days to create a simple system to add a object, (cube for example) next to another object's face the same way minecraft does it. Anyone have any ideas? Probably share a bit of code?

I answered a similar question recently (maybe it was yours)?

Anyway, to do something like Minecraft, you probably want to use a grid system in order to ensure that the results are deterministic (rather than, for example, computing the coordinates for the new cube relative to the coordinates of another cube).

With this method, each cube would have its own integer 'grid coordinates'; the actual world position would then just be a scalar multiple of the grid coordinates (possibly with other transformations applied if desired).

When raycasting against a cube, you'll get a normal back if there's a hit. From this normal, you can determine what side of the cube was hit, and also in which direction in 'grid space' the corresponding neighboring grid cell is. You can then create a new cube in that grid space.

Posting this like for the 5th timeā€¦ First get mouse raycast, than when player presses for example LMB it instantiates a block and stores it into a var and than rounds that number to the grid size.

block.position.x = Mathf.Round(actualBlock.position.x);
block.position.y = Mathf.Round(actualBlock.position.y);
block.position.z = Mathf.Round(actualBlock.position.z);