- Home /
Set Material Emission in C# Editorscript
I can set the Emission and EmissionColor through Code with these two lines:
materials[i].SetColor("_EmissionColor", kvp.Value);
materials[i].EnableKeyword("_EMISSION");
But as soons as I select the GameObject in the SceneView, the Emission disappears. Furthermore "EnableKeyword("_EMISSION")" does not check the Emission checkbox. If I check the Emission checkbox by hand, the EmissionColor is still correct. My question is, is it possible to enable Emission permanently and check the Emission checkbox by code ?
Answer by Ural · Jan 01, 2018 at 09:16 AM
This is working for me. I'm highliting the object when the mouse is over it, and OnMouseExit I agen dissable the key _EMMISSION
private void OnMouseOver()
{
gameObject.GetComponent<Renderer>().material.SetColor("_EMISSION", new Color(0.0927F, 0.4852F, 0.2416F, 0.42F));
gameObject.GetComponent<Renderer>().material.EnableKeyword("_EMISSION");
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Fade emission color using standard shader 1 Answer
Setting texture for a transparent material in c# 0 Answers
Unity Meshes for C# generated objects 0 Answers