How do I change the transparency of objects?

I want to have objects that can become invisible, semi-transparent, and opaque again. Is it possible? If it is, then how? It’s probably obvious but I’m not good at materials and other stuff like that.

Use a material that supports translucency.

  • Alpha 0.0 = transparent
  • Alpha 1.0 = opaque
  • Anything between those = translucent

You can set the colour using Material#color - for example,

this.GetComponent<MeshRenderer>().material.color = new Color(1.0f, 1.0f, 1.0f, 0.5f);

If you’re setting the translucency of a larger amount of objects, it may prove beneficial to share materials between them and set the sharedMaterial.color on one of the objects instead - this change will propagate to other objects sharing that same material, whereas the code above creates a new instance of that material.

If I recall correctly, you are expected to destroy unused material instances when they are no longer needed.