- Home /
Opacity setting from code is not working
I'm an amateur scripter at best so you have my sincerest apologies if there's any novice oversight on my part, but here goes ...
My scene has FX systems comprising of an Empty Parent Object containing four meshes (there are no particles). Each of those meshes are targeting the Particles/Additive (Soft) shader. These polys are also hooked to a script that's scrolling the UV's.
It's all working gangbusters but the systems appearing further off should have some atmospheric perspective. It figures that fading the opacity on these systems would do the job. Easy, right? No! Holy syntax errors Batman! I'm pulling my hair out and kicking furniture trying to get this to happen. Here's the script:
public float opacity = 1.0f;
void Start () {
opacity = gameObject.GetComponent<Renderer>().material.color.a;
}
Errors are "Material doesn't have a color property '_Color' no matter what shader I select, and the other is a MissingComponetException stating there is no renderer though the Mesh Renderer is right next to it in the Inspector stack. Of course, adjusting the provided opacity setting nets nil.
Any help would be greatly appreciated. Argh! :)
Answer by RIw · Mar 30, 2016 at 02:28 PM
Try this:
Color color = GetComponent<MeshRenderer>().material.color;
color.a = 0.1f;
//GetComponent<MeshRenderer>().material.color = color;
Thank you Rlw! I don't mean to sound ungracious or be a bother but it's still not having the desired affect (none actually) with the following error in tow:
$$anonymous$$aterial doesn't have a color property '_Color' UnityEngine.$$anonymous$$aterial.get_color()
Obvious guess is that the shader doesn't have ' Color' in it (Subshader>Pass block?). However there should be something in the shader that can be targeted since the texture is being seen ...?? I dug up a similar texture and applied it. Unfortunately the same error and no affect on the opacity persists, but a peek inside the shader shows a $$anonymous$$ainTex. Is this handling the RGBA ins$$anonymous$$d of _Color? If so, is it possible to target it to get the desired opacity control? I've tried several things but nothing's working.
Stranger is that this message persists with nearly every other shader, but on the 'Standard Shader' it doesn't give the error, but it doesn't change the opacity either. Not to mention it plain out looks like butt.
If you have time to respond I'd be grateful. If not it's understandable. In all though, many thanks.
Your answer
Follow this Question
Related Questions
Water shader with alpha 0 Answers
Alpha Importing Completely White 2 Answers
sprite.associatedAlphaSplitTexture with RGB Crunched ETC1 0 Answers