• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by maikkel · Aug 05, 2011 at 11:29 AM · guiskinguiskin

Global GUISkin?

I have quite a big project with many tests and experiments in over 10 different scenes. I wanted to change the GUI Skin so it would all look a bit better.

Does anyone know of a simple way to globally change the GUISkin?

I did it the hard way now, went into every scene, looked for the GUI-Script and included a public GUISkin-Variable which I then set in the Inspector. This took some time since I often have several GUI-Scripts for the same scene (its all a bit chaotic, but its only for testing after all...)

Comment
Pe-ads
maraoz
senad

People who like this

3 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Molix · Aug 05, 2011 at 02:12 PM

You may want to look into using a 'singleton', or something similar. For example:

 public class MyGuiManager : MonoBehaviour 
 {
   public GUISkin guiSkin;
 
   private static MyGuiManager instance;
 
   void Awake()
   {
     instance = this;
   }
 
   public static GUISkin GetSkin()
   {
     return instance.guiSkin;
   }
 }

As long as you have one game object in your scene with this script, then all your other OnGUI() functions can just call:

 void OnGUI()
 {
   GUI.skin = MyGuiManager.GetSkin();
   // ...
 }

If the game object containing MyGuiManager is in a prefab, then changing the skin for everything only has to happen there.

Comment
Bunny83
maikkel
maraoz
senad
samana1407

People who like this

5 Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Aug 05, 2011 at 03:41 PM 0
Share

Yep, that's the way to go, but you should use DontDestroyOnLoad or you get in trouble after a LoadLevel. Another way would be to copy the guiSkin reference into a static variable so even when the script instance gets deleted the reference is still there.

avatar image Molix · Aug 05, 2011 at 04:07 PM 0
Share

I agree that having one object that lives throughout all LoadLevels is probably better, since you can keep other semi-permanent info too (e.g. window positions), but this way still works (i.e. you can let it get destroyed with the LoadLevel, as long as you have one in the level being loaded, too, since it will be Awake before any OnGUI), and I thought it would be easier to explain without having to worry about ensuring there is only one copy, or loading it manually from Resource, etc.

avatar image maikkel · Aug 05, 2011 at 08:36 PM 0
Share

Thanks for the tip, I'll do it like that. It would still be great if you could change the Default GUISkin in the Project Settings for example...

avatar image maikkel · Aug 06, 2011 at 06:25 PM 0
Share

Works perfectly! Thanks again!

avatar image castor · Sep 09, 2012 at 07:05 AM 0
Share

what is the javascript version of this?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a way to check if the editor is using the Pro skin? 1 Answer

Problems controlling the GUI skin / style 2 Answers

Automatic new line 1 Answer

JavaScript OnGUI GuiSkins aren't working, multiple scripts 1 Answer

How to apply GUI Skins? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges