Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading