Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

GUI.contentColor vs GUIStyle.normal.textcolor?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Abe, Sep 28, 2009.

  1. Abe

    Abe

    Joined:
    Feb 14, 2008
    Posts:
    35
    Hi,
    Iam confusing about using color for displaying text.

    I want to set color for my text as following:

    Code (csharp):
    1.  
    2. GUI.contentColor = Color.red;
    3. GUILayout.Label("red","my_style");
    4. GUI.contentColor = Color.blue;
    5. GUILayout.Label("blue","my_style");
    6.  
    But It is only show black color for my strings.
     
  2. cosmin25

    cosmin25

    Joined:
    Jul 27, 2009
    Posts:
    23
    Code:
    If you use a style the contentColor doesn't work .
    Try this .
    GUI.contentColor = Color.red;
    GUILayout.Label("red");
    GUI.contentColor = Color.blue;
    GUILayout.Label("blue");
    You can use 2 different styles to obtain the same result
     
    Dest8 likes this.
  3. Abe

    Abe

    Joined:
    Feb 14, 2008
    Posts:
    35
    Thank cosmin25 for fast replying.

    At present, I am using two different GUIStyle to show.

    I want to use GUIStyle because I have setting as Padding and Margin.

    I think, when we don't set any GUIStyle at GUIStyle parameter of GUILayout.Label, Unity will use default Label GUIStyle. So I made mystyle the same with default setting, but It is not work as about.
     
  4. cosmin25

    cosmin25

    Joined:
    Jul 27, 2009
    Posts:
    23
    You are right if you don't put the style it uses the default style .
    This is what you want ?
    public GUIStyle mystyle;
    void OnGUI()
    {
    mystyle.normal.textColor = Color.red;
    GUILayout.Label("red",mystyle);
    mystyle.normal.textColor = Color.blue;
    GUILayout.Label("blue",mystyle);
    }
     
  5. Abe

    Abe

    Joined:
    Feb 14, 2008
    Posts:
    35
    Right, Thanks!
     
  6. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    361
    The style will be multiplied by the color applied by GUI.contentColor.

    So if you have black text, and set the contentColor to red, it will not work (as of Unity 2020)
    You need to set a style color to white.