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! :slight_smile:

Try this:

Color color = GetComponent<MeshRenderer>().material.color;
color.a = 0.1f;
//GetComponent<MeshRenderer>().material.color = color;