- Home /
Negative Color Scheme
I'm making a game, and I want there to be an option in the settings to change the color scheme to a negative view, similar to if you press ctrl+option+command+8 on a mac. I was talking it over with my friend and the only thing we were able to figure out is to manually change the values. For example, if on the RGB spectrum the color was 0, 255, 0 then the negative color scheme would make it 255, 0, 255. Is there any simpler way to do this? Thanks for your help.
Answer by Eric5h5 · Jun 09, 2011 at 11:28 PM
Do you just want a function for inverting colors? Or something else?
function InvertColor (color : Color) : Color {
return Color (1.0-color.r, 1.0-color.g, 1.0-color.b);
}
So:
var myColor = Color.red;
var myInvertedColor = InvertColor (myColor);
That would work great, it's a lot more efficient than what I was going to do. However, would I have to have a variable to do this with each object or material (I'm not sure which one) in the scene or is there a way I could make it work for all objects with only one variable?
@Ryan 8: You could make a function which gets all the materials and inverts the colors:
function InvertAll$$anonymous$$aterialColors () {
var renderers = FindObjectsOfType(Renderer);
for (render in renderers) {
if (render.material.HasProperty("_Color")) {
render.material.color = InvertColor (render.material.color);
}
}
}
Answer by VictorAbarca · Sep 27, 2018 at 04:20 PM
I thinks this way is better, more real.
function InvertColor (color : Color) : Color {
var maxColor = color.maxColorComponent
return Color (maxColor-color.r, maxColor-color.g, maxColor-color.b);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612102155im_/https://answers.unity.com/themes/thub/images/avi.jpg)