How to make two blocks interact

So basically I have a game which randomly spawns blocks in a 3D area. When two specific blocks happen to spawn next to each other I would like them to become one different block, which I will specify of course. Can anyone help? Thanks in advance!

There’s a few ways that come to mind how you could do it depending on how you’re spawning your blocks and the different types of blocks required.

One way is to simply store the previous block type in a variable, so that when you place the next block, you can look back to see what the previous block type is, and spawn the next one accordingly.

Another way is you could iterate through all of your placed blocks and send a raycast out of each side of a placed cube. Each cube would have a tag stating what type of block it is. And this way, the raycast can detect what block is beside the placed block, and depending on what the tag is, it can change accordingly.

There are other approaches as well but I think it depends on the specifics of your blocks, how you’re spawning them, and the different types of block joins you want to do.