- Home /
Change text colour in game using the colour spectrum.
Hello, I am trying to use sliders in order to change the colour of my text to help people with visual impairments customise the game. Is there a way to access the spectrum while in game to change the colour or is there a way to set r/g/b to three sliders to change the colour?
Thanks!
Surely you could have three values for R,g,b and then clamp between the max and $$anonymous$$, and create the slider with gui objects, measure the distance the slider is at and assign values from that.
Wouldn't be a spectrum, that would require some extra coding
You could just create a sectrum image, and then calculate the colors with the mouse pos.
Answer by Eric5h5 · Dec 02, 2012 at 07:19 PM
See here for an example of RGB sliders. For a spectrum, a simple way would be to make a texture with the spectrum and then use GetPixel to determine the color.
I used the RGB sliders and have them on screen and changing the colour within the editor but I cannot get them to change my text colour. I used GUI.color = myColour and also tried GUI.contentColor = myColour.
Where am I going wrong with it?
Thanks.
Thanks to everyone that posted something but these two bits of info from Eric and Dark worked for me.
Once again, thank you very much!
Answer by TheDarkVoid · Dec 02, 2012 at 07:27 PM
Use this to do exactly that. You will need to modify the Rects to fit your case
GUI.Label(new Rect(215, 15, 100, 20), "Color: ");
Texture2D previewTex = new Texture2D(1, 1);
previewTex.SetPixel(0,0, curColor);
previewTex.SetPixel(1,1, curColor);
previewTex.Apply();
GUI.DrawTexture(new Rect(215, 40, 75, 75), previewTex, ScaleMode.ScaleToFit);
GUI.Label(new Rect(295, 30, 270, 20), new GUIContent("R: ", "The red value, adds red to the color"));
curColor.r = GUI.HorizontalSlider(new Rect(315, 35, 200, 20), curColor.r, 0, 1);
float.TryParse(GUI.TextField(new Rect(525, 30, 100, 20), curColor.r.ToString()), out curColor.r);
GUI.Label(new Rect(295, 55, 270, 20), new GUIContent("G: ", "The green value, adds green to the color"));
curColor.g = GUI.HorizontalSlider(new Rect(315, 60, 200, 20), curColor.g, 0, 1);
float.TryParse(GUI.TextField(new Rect(525, 55, 100, 20), curColor.g.ToString()), out curColor.g);
GUI.Label(new Rect(295, 80, 270, 20), new GUIContent("B: ", "The blue value, adds blue to the color"));
curColor.b = GUI.HorizontalSlider(new Rect(315, 85, 200, 20), curColor.b, 0, 1);
float.TryParse(GUI.TextField(new Rect(525, 80, 100, 20), curColor.b.ToString()), out curColor.b);
GUI.Label(new Rect(295, 105, 270, 20), new GUIContent("A: ", "The alpha value, controls transparency"));
curColor.a = GUI.HorizontalSlider(new Rect(315, 110, 200, 20), curColor.a, 0, 1);
float.TryParse(GUI.TextField(new Rect(525, 105, 100, 20), curColor.a.ToString()), out curColor.a);
Answer by difd 9999 · Dec 02, 2012 at 07:17 PM
In js Color.red Color.Green Ect. Hope I could help ps. Accept answers for more karma and answers
Your answer
Follow this Question
Related Questions
Change material color with a three slider 2 Answers
GUI slider controls sunlight color? 3 Answers
using rgb to change color c# 1 Answer
Set base color of a specific material 1 Answer
Horizontal Slider Normal-Background Change Color Independently 3 Answers