首页 > 解决方案 > Unity 2018.3 HDRP - 以编程方式更改材质颜色?

问题描述

我正在使用新的 HDRP/LitTesselation 着色器。

我想Base Color + Opacity在运行时更改:

图像

我将此代码添加到游戏对象的脚本中:

void start()
{
        Color color = new Color(100, 50, 100, 150);

        //Fetch the Renderer from the GameObject
        Renderer rend = GetComponent<Renderer>();

        //Set the main Color of the Material to green
        rend.material.shader = Shader.Find("_Color");
        rend.material.SetColor("_Color", color);
}

Hidden/InternalShaderError但它会在着色器中产生错误。谁能指出我正确的方向?

标签: c#unity3d

解决方案


我通过如下修改这些行来使其工作:


rend.material.shader = Shader.Find("HDRenderPipeline/LitTessellation"); 
rend.material.SetColor("_BaseColor", color);


推荐阅读