Hans
Hans

Reputation: 2502

Set the color of an object in unity

I am trying to generate randomly colored trees in Unity in C#. The Line of Code I have is:

stemObject.GetComponent<Renderer>().material.color = StemCol;

It will the first time color it pink or light blue (though it is not the specified color), and when restarting the script always white, until the script is executed once without the line.

Without the line there is a very normal shading.

I also tried this

Color[] cols= new Color[m.vertices.Length];
for (int i = 0; i < m.vertices.Length; i++) {
    cols[i] = StemCol;
}
stemObject.GetComponent<MeshFilter>().mesh.colors = cols;

but it didn't have any effect at all.

How do I change the color of the object without the weird shading, and in the right color? shading without the script pink shading - though not the selected color WHITE BUG

Upvotes: 0

Views: 1853

Answers (1)

Hans
Hans

Reputation: 2502

Ok, I figured it out: Unity colors are 0-1, not 0-255, so everything was very bright

Upvotes: 2

Related Questions