- Home /
Alpha on a GameObject?
Is it possible to define the master visibility of a GameObject/mesh renderer? I am vaguely aware that fading a mesh out can be done by getting its material and changing the alpha value of it. However, perhaps my Blitz Basic 3D legacy has spoilt me with this feature, but I like the idea of an object opacity variable. Is there anything like this in Unity? For example, if I have a hypothetic complex object with dozens of materials it seems clumsy getting them all and fiddling with the alpha.
Is there a much better way to fade out a mesh that I am overlooking?
Answer by $$anonymous$$ · Nov 20, 2009 at 07:55 AM
You could write a script with a single opacity variable and code that iterates through the materials of the game object it's attached to (e.g. via renderer.materials) and adjusts the alpha of each one.
I should probably add for the benefit of others seeking this, that it took me a while to realise you need to use a Transparent shader (either one of your own or one in the "Transparent" grouping) for the object's material. Correct me if I'm wrong here.
Answer by robert · Nov 20, 2009 at 08:53 AM
technicat is right, this is the way to go.
When you're there, you might also consider using the two pass transparency shader to get rid of the overlapping polygons artifacts.