- Home /
Acces to a material issue
Hello
I'm trying to acces to my material with a script
It can seem simple but I cant set the emission color with the code below, it just doesn't works
( I have an instance which have the material on the scene before the playmode starts )
private Material matBane;
private Color colort1 = new Color(.2f, .1f, 0, 1);
void Start()
{
matBane = GetComponentInChildren<SkinnedMeshRenderer>().material;
}
public void SetColor()
{
matBane.EnableKeyword("_EMISSION");
matBane.SetColor("_EmissionColor", colort1);
}
Hi. You can debug with material.Is$$anonymous$$eywordEnabled("_E$$anonymous$$ISSION") and material.GetColor("_EmissionColor") . Also material returns first attached one, see if you have more than one.
Yep, sound like the material which is returned is not the expected one
$$anonymous$$y bad, I didnt check that and yet that was the problem
Thank you!
Answer by Strixie13 · Jul 12, 2018 at 02:13 AM
Try changing the material through the renderer. Any color should work, just threw the blue in as an example.
private void Start()
{
gameObject.GetComponent<Renderer>().material.EnableKeyword("_EMISSION");
gameObject.GetComponent<Renderer>().material.SetColor("_EmissionColor", Color.blue);
}
Your answer
Follow this Question
Related Questions
material.SetColor ("_EmissionColor", Color.white) 1 Answer
Change emission with script 0 Answers
lerp between emission colours 2 Answers