How can I change the material of an object through a script in unity?

I am making a script in unity where if you hit a button the door opens and the light above the door turns green signifying that the door is now open, so how can I change the material/color of that light through a script?

>Solution :

Changing material of the object:

someObject.GetComponent<Renderer>().material = customMaterial;

Changing color of the object:

Color someColor = new Color(0.5f, 0.4f, 0.3f, 1.0f);
someObject.GetComponent<Renderer>().material.SetColor("_Color", someColor);

Leave a Reply