If you’re looking to snap these items together like in fornite then there’s a specific technique you can use involving putting empty gameobjects that act like nodes onto each side of your gameobject, this same technique I think could be used in 2D.
Be warned though it is a fairly deep topic you’re asking about.
For the game I created not long ago, I did a socket design very similar to what’s posted by @Lethn above.
A building block would have a bunch of empty child gameobjects which would act as a socket. The sockets would be positioned prior to run time.
Each socket had a script on it that contained a list of buildingblocks that it would accept.
I then just used a raycast from the players camera forward position to check whether sockets were available or not and would place a preview block if so.