我正在使用新的 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
错误。谁能指出我正确的方向?
最佳答案
我通过如下修改这些行使其工作:
rend.material.shader = Shader.Find("HDRenderPipeline/LitTessellation");
rend.material.SetColor("_BaseColor", color);
关于c# - Unity 2018.3 HDRP - 以编程方式更改 Material 颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54281575/