Olie
November 10, 2010, 10:52pm
1
I'm doing a simple box-add, and the alpha in the color doesn't seem to work. Code:
var fieldBox : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
fieldBox.transform.parent = this.transform;
fieldBox.transform.renderer.material.color = Color.blue;
fieldBox.transform.renderer.material.color.a = 0.05;
It just comes out solid blue. I'd expect something that was 95% transparent. What simple n00b mistake am I making?
Thanks!
Eric5h5
November 10, 2010, 11:02pm
2
You need to use a shader that has transparency. The default diffuse shader doesn't.
Olie
November 11, 2010, 1:33am
3
The immediate answer to the question that I asked is: the default shader does not do transparency. +1 to Eric5h5 for that.
However, the useful answer that I was looking for (and eventually found, but after a long-ish search!) was that I want to include this line:
fieldBox.renderer.material.shader = Shader.Find( "Transparent/Diffuse" );
In the code above. So the whole thing looks like this:
var fieldBox : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
fieldBox.transform.parent = this.transform;
fieldBox.transform.renderer.material.color = Color.blue;
fieldBox.transform.renderer.material.color.a = 0.05;
fieldBox.renderer.material.shader = Shader.Find( "Transparent/Diffuse" );
There are, of course, a variety of shaders and more efficient ways to get at them than Find(), but this is the answer for someone just looking to put a transparent cube on their early-on n00b project -- "how hard can it be?!"