- Home /
Change color of object
Hi
I am new to unity. I am trying to change the color of my object, and I want to assign it to a button, so when I click the button, color changes to the specific RGB that I enter manually. I have searched but didn't get what I need. can anyone help ?
are you using your own buttons or the GUI.Button from native gui?
I am using plane with box collision that is child of the object as button.
Answer by fueldown · Jul 11, 2014 at 03:24 AM
ok. then you can change the color (by defining rgba values) of the object as follows:
Color myColor = new Color(r,g,b,a);
Transform parentObject = this.transform.parent;
if(myButtonClicked == true){
parentObject.renderer.material.color = myColor;
}
Oh, btw, don't use plane. It has 100 tris. Not necessary for a measly button. Use Quads. Only 2 tries. :)
is this parentObject refers to the object that my button is child of it or I should place name of the object ins$$anonymous$$d ?
and myButtonClicked, how it works ? I am a little bit confused :(
sorry for asking so many questions, my object is made of separate parts, how to control the color of each part ?
You can control the colour with same logic for every separate item that you wish to change the colour for. As for the mybuttonclicked, it is just some Boolean you have to get by either implementing touch on your button or using native Unity GUI.
Your answer
![](https://koobas.hobune.stream/wayback/20220613153737im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
CS0029 convert type 1 Answer
Object color change 0 Answers
Reset Button 1 Answer
Help me enable the Collider as soon as the game renders that GameObject 1 Answer