putting 4 cubes together to make one bigger cube

is there anyway to make like cubes a bigger one when their all together. not only cubes other things like rocks or other objects.

an idea of what im looking for its like if u have number of rigidbodys and when they are in an area or if they are close to each other they would transform into something else

Depends on the effect you want.

  1. If you simply want to pack the objects together and move them around in unison, you can parent them with a new gameobject, or make one the parent. When the parent moves, the rest move too.

  2. You can hide or destroy the originals and replace them with a new object that already exists. This would be the best way if performance were an issue, or if the combined object needed to look different, like replacing a player's ship + powerup with a fancier ship.

  3. It is also possible to create a new mesh at runtime. This could be programmatically done by your game by reading the meshes of the objects that are being combined, and merging them somehow.

Most games will use either #1 or #2. (If you need the arbitrary combinations given by #1, such as for a Katamari game, you have the option of trying #3 later on if performance becomes an issue.)

You could either detect if they are close to each other using a trigger boxcollider or react to a collision between to objects. Then you could either establish a parent-child relation through their transforms (transform.parent = otherTransform) or you could link the two rigidbodies using a fixedjoint.