Changing the alpha of Mesh Renderer

Hi, I am trying to make a certain item blink when time is almost expired. I want to change the alpha to 0 but the opacity does not change at all.

I did it this way:

itemWeapon.GetComponentInChildren<MeshRenderer>().material.color = new Color(1f,1f,1f,0f);

I tried to print the color out and it says RGBA(1.000, 1.000, 1.000, 0.000) but the object is still very visible.

Your code is perfectly fine. The shader on your object doesn’t support alpha. i tried transparant/ Bumped diffuse and that one seemed to work. you can try other shaders for yourself :wink:

edit: to add to my comment i’d assume that you already have a material added to your gameobject?

colour.a = 0;

You need to use a shader that supports transparency, but it would be better to simply disable the renderer instead.

To make @smashingy0u’s answer a little clearer, as long as there is a material on your Mesh Renderer, you can just do something like this to make a text mesh invisible:


TextMeshGamObject.GetComponent<MeshRenderer>().material.color = new Color(1f, 1f, 1f, 0f);