Home > Blockchain >  Shader Change during runtime
Shader Change during runtime

Time:08-24

I am trying to change shader on a trigger event during run time. However, when I used Debug.Log to check if all is right or wrong and everything runs except the shader does not change. There is something I missed ? Any help could be appreciated. Thanks very much

public void shaderChange() 
{
    rend = gameObject.GetComponent<Renderer>();
    shader1 = Shader.Find("Standard");
    shader2 = Shader.Find("Shader2");

    isActiveClip = !isActiveClip;
    if(isActiveClip == true)
    {
        rend.material.shader = shader2;
    }
    else
    {
        rend.material.shader = shader1;
    } 
}

CodePudding user response:

The proper way to manipulate shaders is to change the assigned materials on the object. This means instancing a material for each use case and switching materials at runtime. This is because the material itself is dependent on the shader when being created.

  • Related