- Home /
How do you change the color of a simple cube in Unity 5.0?
I've seen all these videos and they are telling me do:
gameObject.renderer.material.color
But the problem is that the material part doesn't show up. Then I came across the fact that this line of code is deprecated, so now I'm stuck. I found something that should have helped:
var rend = GetComponent();
But now what do I do? I just want to change the color of a cube, so please don't make anything really complicated I'm just a beginner.
Answer by YoungDeveloper · Aug 02, 2015 at 02:39 AM
gameObject.GetComponent<Renderer>().material.color = Color.red;
how come if you set that code to be equal to new Color(102, 153, 255); it wont work?
i mean, this doesn't work: gameObject.GetComponent().material.color = new Color(102, 153, 255);
is there any way to pass a rgb value ins$$anonymous$$d of using Color.nameofcolor ?
mmm i found an answer. It says you need to pass values from 0.0 to 1.0 for new Color(r,g,b) to work :)
Answer by eirikamb · Jun 21, 2016 at 09:30 PM
Thinking about Frames per Second I would recommend using .Sharedmaterial.color etc
Your answer
![](https://koobas.hobune.stream/wayback/20220611234044im_/https://answers.unity.com/themes/thub/images/avi.jpg)