Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Problem with gui.skin

Discussion in 'Immediate Mode GUI (IMGUI)' started by sylvied, Apr 20, 2014.

  1. sylvied

    sylvied

    Joined:
    Apr 4, 2014
    Posts:
    3
    Hey guys,

    I'm trying to change the gui.skin to another skin but I've tried it for several times but it doesn't seem to work.
    When adding a new skin I don't receive the same icon that I see with people over the internet, I've uploaded a screen shot of the icon I receive.
    $ScreenShot.png
    I'm very new to Unity so it's possible that It's just a simple mistake but I'm not sure. Is it because I'm running Unity Free?
    I've made a script with this code :

    public GUISkin customSkin;
    void OnGUI()
    {
    GUI.skin = customSkin;
    print("customSkin setted");
    }

    I attached this script with my Main Camera and attached the new skin to it. He does print '' print("customSkin setted");''

    Anybody who can help me?
    Thanks!
     
  2. Beennn

    Beennn

    Joined:
    Sep 11, 2010
    Posts:
    373
  3. sylvied

    sylvied

    Joined:
    Apr 4, 2014
    Posts:
    3
    Hey Beennn,

    I know that it doesn't affect my console, but the fact that he writes to the console means that he did change the skin, I have all kinds of buttons, toggles, labels in my project but the skin isn't applied to it..
     
  4. Beennn

    Beennn

    Joined:
    Sep 11, 2010
    Posts:
    373
    You didn't check if it was set, you just printed a message, which would print with or without the skin being set. You'd do something like:
    Code (csharp):
    1.  
    2.     void OnGUI () {
    3.  
    4.         GUI.skin = testskin;
    5.  
    6.         if (GUI.skin != testskin)
    7.             return;
    8.  
    9.         print ("skin was applied");
    10.    
    11.     }
    12.  
    To check if the skin had been set.
     
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Try setting GUI.skin = customSkin at the beginning of all of your OnGUI() methods that need to use the custom skin.

    As a test, change your script to:
    Code (csharp):
    1.  
    2. public GUISkin customSkin;
    3. void OnGUI()
    4. {
    5.     GUI.skin = customSkin;
    6.     print("customSkin setted");
    7.     GUILayout.Label("This is a label");
    8.     GUILayout.Button("This is a button");
    9.     // If you've defined custom styles, add controls for them here.
    10. }
    11.  
    When you run this, does it use the custom skin?

    Also, when posting code, please read about Using code tags properly.
     
  6. sylvied

    sylvied

    Joined:
    Apr 4, 2014
    Posts:
    3
    Hey TonyLi,

    Thanks for your response, I didn't know that I had to apply it to each script so Problem Solved! Thank you very much!
     
  7. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Happy to help!