c# - Unity 2018.3 HDRP - 以编程方式更改 Material 颜色?

标签 c# unity3d

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

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

img

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

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/

相关文章:

c# - 覆盖文件权限 - C#/ASP.NET

unity3d - 在 Unity 3D 中移动游戏对象的最佳方式

c# - 以 Child 类型作为参数的方法的继承类 : wrong method being called

c# - 如何下载存储在sql server中的图像

c# - 嵌套 "from"用扩展方法表示的 LINQ 查询

c# - 如何创建以终点为鼠标位置但仅面向一个方向的线渲染器

c# - 按钮 onClick 不会与对象发生碰撞

c# - Unity (Unity5) 中 c# 中的属性 - 你能避免支持变量吗

c# - 向 DataGridViewCell 添加自定义控件

c# - ViewBag 属性已设置但不可访问