Skip to main content
added 581 characters in body
Source Link
Mangata
  • 2.8k
  • 1
  • 4
  • 10

First of all, It is strongly recommended that you use the updated unity GUI tools. Check UI-system-compare.

Back to this question. Let's look at the definition of GUI-backgroundColor:

Global tinting color for all background elements rendered by the GUI.
This gets multiplied by color.
  1. It's a global value for all elements.
  2. It's not the element color but a "correction value". Just like "multiply blend mode" in photoshop.

Maybe this button Need to have its own GUIStyle object. Try this:

    var playButtonStyle = new GUIStyle(GUI.skin.box);
    if (test == false)
    {
        playButtonStyle.normal.background = MakeTex(2, 2, Color.red);
        test1 = "STOP";
    }
    else
    {
        playButtonStyle.normal.background = MakeTex(2, 2, Color.green);
        test1 = "PLAY";
    }
    if (GUI.Button(new Rect(10, 130, 170, 30), test1, playButtonStyle))
    {
        Debug.Log("Clicked the button with text");
        test = !test;
    }

Another way:

    var defaultColor = GUI.color;
    if (test == false)
    {
        GUI.color = Color.red;
        test1 = "STOP";
    }
    else
    {
        GUI.color = Color.green;
        test1 = "PLAY";
    }
    if (GUI.Button(new Rect(10, 130, 170, 30), test1))
    {
        Debug.Log("Clicked the button with text");
        test = !test;
    }
    GUI.color = defaultColor;

Modify the global color of GUI and restore it after use. This preserves the style of the default button.

First of all, It is strongly recommended that you use the updated unity GUI tools. Check UI-system-compare.

Back to this question. Let's look at the definition of GUI-backgroundColor:

Global tinting color for all background elements rendered by the GUI.
This gets multiplied by color.
  1. It's a global value for all elements.
  2. It's not the element color but a "correction value". Just like "multiply blend mode" in photoshop.

Maybe this button Need to have its own GUIStyle object. Try this:

    var playButtonStyle = new GUIStyle(GUI.skin.box);
    if (test == false)
    {
        playButtonStyle.normal.background = MakeTex(2, 2, Color.red);
        test1 = "STOP";
    }
    else
    {
        playButtonStyle.normal.background = MakeTex(2, 2, Color.green);
        test1 = "PLAY";
    }
    if (GUI.Button(new Rect(10, 130, 170, 30), test1, playButtonStyle))
    {
        Debug.Log("Clicked the button with text");
        test = !test;
    }

First of all, It is strongly recommended that you use the updated unity GUI tools. Check UI-system-compare.

Back to this question. Let's look at the definition of GUI-backgroundColor:

Global tinting color for all background elements rendered by the GUI.
This gets multiplied by color.
  1. It's a global value for all elements.
  2. It's not the element color but a "correction value". Just like "multiply blend mode" in photoshop.

Maybe this button Need to have its own GUIStyle object. Try this:

    var playButtonStyle = new GUIStyle(GUI.skin.box);
    if (test == false)
    {
        playButtonStyle.normal.background = MakeTex(2, 2, Color.red);
        test1 = "STOP";
    }
    else
    {
        playButtonStyle.normal.background = MakeTex(2, 2, Color.green);
        test1 = "PLAY";
    }
    if (GUI.Button(new Rect(10, 130, 170, 30), test1, playButtonStyle))
    {
        Debug.Log("Clicked the button with text");
        test = !test;
    }

Another way:

    var defaultColor = GUI.color;
    if (test == false)
    {
        GUI.color = Color.red;
        test1 = "STOP";
    }
    else
    {
        GUI.color = Color.green;
        test1 = "PLAY";
    }
    if (GUI.Button(new Rect(10, 130, 170, 30), test1))
    {
        Debug.Log("Clicked the button with text");
        test = !test;
    }
    GUI.color = defaultColor;

Modify the global color of GUI and restore it after use. This preserves the style of the default button.

Source Link
Mangata
  • 2.8k
  • 1
  • 4
  • 10

First of all, It is strongly recommended that you use the updated unity GUI tools. Check UI-system-compare.

Back to this question. Let's look at the definition of GUI-backgroundColor:

Global tinting color for all background elements rendered by the GUI.
This gets multiplied by color.
  1. It's a global value for all elements.
  2. It's not the element color but a "correction value". Just like "multiply blend mode" in photoshop.

Maybe this button Need to have its own GUIStyle object. Try this:

    var playButtonStyle = new GUIStyle(GUI.skin.box);
    if (test == false)
    {
        playButtonStyle.normal.background = MakeTex(2, 2, Color.red);
        test1 = "STOP";
    }
    else
    {
        playButtonStyle.normal.background = MakeTex(2, 2, Color.green);
        test1 = "PLAY";
    }
    if (GUI.Button(new Rect(10, 130, 170, 30), test1, playButtonStyle))
    {
        Debug.Log("Clicked the button with text");
        test = !test;
    }