|
Hi, I have a cube which has its box collider set to 'is Trigger' and a Rigidbody component (to make the Trigger work) which moves forward towards some stationary objects which also have box collider components. I am going to have a camera moving towards these objects and want the objects to fade to transparent when they approach. For this, I have created a trigger that will cause any objects that collide with it to gradually become transparent. So far, the trigger detects the objects fine and on doing so creates a temporary renderer object to reference each object's renderer. I then create a Color object with transparency to apply to their renderer. Now, the objects change colour just fine but their alpha does not change. I have a suspicion that I have to use a shader for this, but am not sure how to apply one if this is the case. Also, if anyone can suggest a more elegant method for fading objects approaching the camera then that would be great too. I would like to try to avoid using iTween as am trying to learn the ropes. Thanks in advance.
(comments are locked)
|
|
Try changing to Does it work? if not, try tempRenderer.materials[0].color = whatever ; renderer materials is an array Edited : (I didn't read your question until after I read the posted answer and commented) ... some shaders don't have alpha or allow it's alpha to be accessed through '.color.a' etc ; if you're getting colors to change, but not alpha values, try a different shader and see if that's the problem.
Apr 17 '12 at 08:17 PM
Lo0NuhtiK
Yeah you need to use a transparent shader. Either switch materials at the beginning of the fade, or render transparent the whole time. I don't recommend using a transparent shader the whole time, though, because you can sometimes get weird and frustrating z-sorting issues.
Apr 18 '12 at 02:28 AM
syclamoth
(comments are locked)
|
|
Hi Kevin, Thanks for your suggestion, they both work which is great. The main problem appeared to be that I needed to have a Transparent Shader type for the material applied to the Obstacles in order to change the Alpha value. I was using the default Diffuse Shader. Yes, I forgot to tell you that! It happened to me a few weeks ago, and I also realized that I need to use a shader with transparency, otherwise it doesn't work. Glad to help!
Apr 18 '12 at 02:22 AM
kevinseligmann
(comments are locked)
|
