Find a Editor Gui Label and set its color

Hey,

is it possible to find out via Editor Script what Label ( GUIobject ) is selected in the Hierarchy and modify its color / backgroundcolor ?
I search for 2 days now… :confused:

i can’t finger it out how to modify existing Editor GUI element.

Thx for any tips!

What you can do is to give a tag to an GUI Element and than check if it’s selected.

if (GUI.GetNameOfFocusedControl() == "numberField"){
      GUI.backgroundColor = Color.blue;
}

GUI.SetNextControlName("numberField");
number = EditorGUILayout.FloatField(number);

GUI.backgroundColor = Color.white;

i don’t know if there’s another easier way because you have to name every control you want to check for.

You could also create a custom GUI style with a different active color.

1 Like

Ah nice thanks, haven’t this yet :slight_smile:

In the case of wanting to have a different color of the text label based on which script is attached to the object, how would you assign the color based on that condition?