OnGUI() Text Color through c# script
Hi there, been stuck on this for a while, searched possibly every question in relation to this and cannot find anything that will help nor work..
what i am trying to achieve is make the Text bigger, which is done by the guiStyle, but after doing this, it turned the text to Black from white, and i have a dark Horror scene so the text is now unreadable, it was near unreadable being the default size, and now it is a good size to read, but it has turned black and has become unreadable in that way...
and once again, i have searched around and tried many different ways, with GUISkins (which if someone could provide a good way to use these, as the Unity source code page on this did not help me much), using GUI.color = Color.white, i believe it is the guiStyle that is overwriting the color to be black, just wondering how i can either default it back to the default white or change it somewhere to allow it to be white in my coding?
private GUIStyle guiStyle = new GUIStyle();
void OnGUI()
{
GUI.color = Color.white;
guiStyle.fontSize = 20;
//have tried GUI.color here
if (isRinging)
{
//have tried GUI.color here
GUI.skin.label.alignment = TextAnchor.UpperLeft;
//have tried GUI.color here
GUI.Label(new Rect(10, 10, 1500, 900), "Task: Answer The Phone.", guiStyle);
}
Answer by Glurth · Jan 17, 2017 at 06:41 PM
I suspect this issue is due to the fact that you create a new GUIStyle, and use it for your label, but you do NOT assign this style a specific color. Since creating it yourself, you actually need to define the color for each GUIStyleState in the GUIStyle (normal, hover, etc..). e.g.
guiStyle.normal.textColor= Color.white;
Regarding GUI.color, I suspect you meant to use GUI.contentColor. But I think the GUIStyles is the better way to go.
Excellent, thanks very much, i was trying my best to work this out, i did try similar code to that, but without the .normal. that's where my problem was, thank you!
EDIT: and yes i did actually try and use GUI.contentColor, but that had no effect, but as we had both suspected i believe the guiStyle was overwriting the color.
Your answer
Follow this Question
Related Questions
Animating Colors fails 0 Answers
How do i make an Image flash 2 colors, 1 Answer
TextBox.Color C# logic not working for two assets at once 0 Answers
Is there any way to make a gradient within unity?,Is there any way to make a gradient? 1 Answer
How to make a TextMeshPro Object perfectly fit his RectTransform's height ? 0 Answers