Search Unity

click on button changes button style

Discussion in 'Immediate Mode GUI (IMGUI)' started by giulioandrea, Jul 15, 2008.

  1. giulioandrea

    giulioandrea

    Joined:
    Feb 16, 2006
    Posts:
    72
    last thing, when I click on a button I would like to change the colour of it until something else happens.
    At the moment I am using a translucent empty text box on the top of the button... but I am sure there is a more elegant way to do this.
    Any idea where to start?
    For instance if I had to change this


    Code (csharp):
    1.  
    2. var mySkin : GUISkin;
    3. function OnGUI() {
    4.     GUI.skin = mySkin; 
    5.     GUI.Box (Rect (10+L1,10,150,125+20), "Layout Selection");
    6.  
    7. if (GUI.Button (Rect (25+L1,20+45+LL1,120,20), "5 Mullions")) {
    8. B100 = true;
    9. }
    10.  
    11.     if (B100) {
    12. //this adds the translucent stuff on the button '5 mullions'
    13.         GUI.Box (Rect (10+L1,20+45+LL1-5,150,35), " ");
    14.         GUI.Box (Rect (10+L1,20+45+LL1-5,150,35), " ");
    15.         GUI.Box (Rect (10+L1,20+45+LL1-5,150,35), " ");
    16.  
    17.         GUI.Box (Rect (10+L2,10,150,125+20), "Tilt Selection");
    18.  
    19.         if (GUI.Button (Rect (25+L2,20+45+LL1,120,20), "+45")) {
    20.         B110 = true;
    21. }
    22.         if (GUI.Button (Rect (25+L2,20+45+LL2,120,20), "0")) {
    23.         B120 = true;
    24. }
    25. }
    26.  
    27.  
    28.  
    29.  
     
  2. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Have you looked in the manual? It's pretty useful.
    Try GUI.color and GUI.backgroundColor. Wrap these around the controls you want to change.
     
  3. giulioandrea

    giulioandrea

    Joined:
    Feb 16, 2006
    Posts:
    72
    I will check it out next week...
    I have a very close deadline and not time to seek 'the knowledge'.
    I am keeping the solution of the multilayered transparent box...
    not elegant but working for me.
    Anyway thanks for the hint!
    G>