Making an object transparent

I'm a game where you can build things. When placing the things they should be half transparent(a = 0.5) until they are placed. How do I do this? I seen an answer to similar problem is

Color c = renderer.material.color;
c.a = 0.5f;
renderer.material.color = c;

But the problem is the object can contain many meshes with many textures and I want it to be overall transparent, e.g. if an object is a box behind a box, the box behind will not be seen through the front box.

The solution should be rendering everything within the object, halving the alpha, and putting it in the scene, but I don’t know how.
How do I do this?

Edit: I realized this can be done by applying a shader to the object.

But I can only find how to attach a shader to a material.

How do I attach a shader to a whole object?

You could use GetComponentsInChildren to find all renderers of all meshes attached to the GameObject and then use a for loop to apply the color like in your script.

If you want to apply a shader to an object you have to create a material, attach the shader to the material and then apply this material to the renderers instead of the color.