Setting emission color in unity

时间:2015-11-12 11:46:32

标签: c# unity3d

I have tried searching for this, but cannot find any solution. I'm setting the color of each object as such:

Color color = Color.red;
float f = 0.4f; 
GetComponent<Renderer>().material.color = color;
GetComponent<Renderer>().material.SetColor("_EmissionColor",color*f);

However, in the game the color is not set unless i select the object and expand the material component. I made a gif illustrating what I mean.

I have tried using the DynamicGI, based on issues that were kind of similar, but nothing works. However, seeing that clicking the material in the unity editor causes it to be updated, the change seems to be registered. The updated materials are just not automatically applied.

1 个答案:

答案 0 :(得分:4)

After many hours of searching, I managed to find a solution just after posting this question.

To fix the issue, simply add

material.EnableKeyword("_EMISSION");