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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Find a Editor Gui Label and set its color

Discussion in 'Immediate Mode GUI (IMGUI)' started by sliverkf, Jul 21, 2015.

  1. sliverkf

    sliverkf

    Joined:
    Mar 10, 2014
    Posts:
    6
    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... :/

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

    Thx for any tips!
     
  2. martinmr

    martinmr

    Joined:
    Mar 25, 2015
    Posts:
    325
    What you can do is to give a tag to an GUI Element and than check if it's selected.

    Code (CSharp):
    1. if (GUI.GetNameOfFocusedControl() == "numberField"){
    2.       GUI.backgroundColor = Color.blue;
    3. }
    4.  
    5. GUI.SetNextControlName("numberField");
    6. number = EditorGUILayout.FloatField(number);
    7.  
    8. 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.
     
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,852
    martinmr likes this.
  4. martinmr

    martinmr

    Joined:
    Mar 25, 2015
    Posts:
    325
    Ah nice thanks, haven't this yet :)
     
  5. Mish

    Mish

    Joined:
    Apr 23, 2010
    Posts:
    96
    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?