- Home /
Why colors are being mixed after I try to change them?
Hi guys, I am currently working on a project where I need to implement the k-means algorithm. First of all I create different game objects in space according to their positions, and then I generate 3 spheres randomly (red, green and blue). After calculating the distance from each data point to each of the spheres, if the data point is closest to the green sphere, then I change the color of the data point to green.
But, in my case, somehow for some reason, some of the data points are not becoming green, but they mix with the color from before and I get darker green. I have tried to change the color using both this code:
child.gameObject.GetComponent<Renderer>().material.color = Color.green;
and then I tried with:
child.gameObject.GetComponent<Renderer>().material.SetColor("_Color", Color.green);
but in both cases for some reason the colors mix, instead of setting it to strong green.
You can see that in the images below.
This is the normal green in the inspector
and this is the darker green in the inspector.
As you can see, both material colors are the same, but the second one is darker..
The previous colors of the game objects were purple and greenish.
Thank you in advance!
you covered the inspector with the $$anonymous$$aterial selector, so we can't see
Double check to make sure the $$anonymous$$aterial property in the inspector is showing the correct color. If the color on the $$anonymous$$aterial is correct, then it's probably a lighting issue. That would be my guess :)
Answer by kliment5 · Aug 18, 2017 at 11:02 AM
Ok, so after many trials I have decided to create my own "Red", "Green", and "Blue" materials, just normal materials with that color. And then in the code instead of changing the color of the previous material, I just assign the proper colored material, something like this :)
// in the inspector with drag and drop I put the previously created red
// material
public Material redMat;
child.gameObject.GetComponent<Renderer>().material = redMat;
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
Adjust tint color of particles/additive? 2 Answers
Material color won't update! 2 Answers
Emissive Material control via script (code) 1 Answer
Changing Material Color Via Script 1 Answer