material color alpha doesn't seem to work.
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!
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?!"
ref : https://answers.unity.com/questions/33556/material-color-alpha-doesnt-seem-to-work.html
'게임엔진(GameEngine) > Unity3D' 카테고리의 다른 글
unity3D Help Shortcut setting + visual studio (0) | 2018.10.13 |
---|---|
유니티 UI 버튼 PointerDown, Up 스크립트로 받아오기 (0) | 2018.10.12 |
How do I make member structs accessible in the editor? (0) | 2018.10.08 |
Physics.BoxCastAll (0) | 2018.10.08 |
How to get a List<> from GetComponents? (0) | 2018.10.07 |
I'm sorry you didn't find my answer sufficient, but I did say "You need to use a shader that has transparency." The second part ("The default diffuse shader doesn't") was merely a qualifier to the more important first part. I figured it would have been fairly obvious that you'd take another look at the shader drop-down list, see the "Transparent" section there, and say "Oh, I get it." Because that is exactly the reaction of several people in the past who've asked this question and gotten the same answer from me. I try to provide only the relevant info rather than wasting your time with fluff.
Also, if you find an answer to be unclear, just post a comment under it saying so, and I'll expand it.
Eric: yeah, good points all. Perhaps I wasn't clear that I was trying to do all of this in script, at which point "use a different shader" is, as I said, technically correct but not helpful. I'm not trying to "start up" with you -- I just noticed that a very many of the answers on this site are like that. I come from a strong StackOverflow background, where the answers are typically more overt, it all. No worries, I'll get the hang of things around here.