Changing mesh shader from standard to transparent standard.

Hi, I was hoping to be able to make an object fade away through code, and to start with, I tried changing the alpha of the object like this gameObject.GetComponent<MeshRenderer>().material.color = new color (1, 1, 1, 0);
But it made no difference.

I was wondering if there’s anything like gameObject.GetComponent<MeshRenderer>().material.shader = Shader.Material.SetActive(false);

that can work? Where you use SetActive?

I got some results with the following code, but my cube, after pressing left mouse button, went PINK. After searching forums, I read about Preferences> GI Cache> Clean Cache, and believing that might help, followed those instructions, but it made no difference.

Still pink when LMB pressed. :slight_smile:

Ideally I would like to be able to change the object from opaque to transparent at afadeFloat * timeDeltaTime, but that was the next part of the problem.

public class Fade : MonoBehaviour
{
    GameObject player;
   


    // Use this for initialization
    void Start()
    {
        player = gameObject;
        GetComponent<MeshRenderer>().material.shader = Shader.Find("Standard");
     
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))

        {
    

           gameObject.GetComponent<MeshRenderer>().material.shader = Shader.Find("Transparent/Standard");
}
}
}

you can lookup the shader property names by selection the shader in the project and clicking on the little cog top right of the inspector and selecting “edit shader” (or something like that).

1 Like

For alpha levels is there anything like color (1, 1, 1, 1) MoveTowards * floatRate * TimedeltaTime new Color (1, 1, 1, 0);?

Lerp?