Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by Earless · Oct 07, 2014 at 07:28 PM · guiguistyle

Using a custom style of GUI.skin

I've read at least 5 posts about this subject, but they didn't have the right answer to solve it. Therefore I make this post.

My problem is as follows: I have a GUISkin used for my menu's. If I have the following OnGUI function, the time is displayed correctly:

 void OnGUI ()
     {
         GUI.skin = skin;
 
         GUI.Label (new Rect (10, 40, 400, 400), "Time: " + currTimer);
     }

However, after I made a custom style called "Time_Label", I wrote this code:

 void OnGUI ()
         {
             GUI.skin = skin;
     
             GUI.Label (new Rect (10, 40, 400, 400), "Time: " + currTimer, skin.GetStyle("Time_Label"));
         }

And now the time doesn't get displayed. What's wrong?

Comment
Add comment · Show 2
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 Graham-Dunnett ♦♦ · Oct 07, 2014 at 07:29 PM 0
Share

Hard to say. What's your skin/style do?

avatar image Earless · Oct 08, 2014 at 09:49 AM 0
Share

$$anonymous$$y skin is nothing special. Just added a GUISkin. $$anonymous$$y style is also not complicated. The name is Time_Label. I added a color to the normal tab. I used the font Arial and font size = 40. This all is correct I think, or not?

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by MichaelARoberts · Oct 07, 2014 at 09:36 PM

Your should put GUI before skin.GetStyle ("Time_Label"));

Something like this:

  GUI.Label (new Rect (10, 40, 400, 400), "Time: " + currTimer, GUI.skin.GetStyle("Time_Label"));
 
 

Comment
Add comment · Show 2 · 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 Earless · Oct 07, 2014 at 09:40 PM 0
Share

But, I wrote 2 lines above: GUI.skin = skin. So that should do the trick, right?

avatar image Tourist · Oct 08, 2014 at 09:54 AM 0
Share

it is still better to comprehend.

You can also use the string name of the style directly :

 GUI.Label (new Rect (10, 40, 400, 400), "Time: " + currTimer, "Time_Label");
avatar image
0

Answer by Tourist · Oct 08, 2014 at 09:57 AM

Try to get the style the line above and check if the style is null.

If it is null, then there is a mismatch on the name. Check there is no space in the name that could cause that. If not, the problems are in the parameters of your style.

Comment
Add comment · 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
0

Answer by Earless · Oct 08, 2014 at 10:20 AM

Everyone, thanks for answering. Apparently I'm very stupid. The alpha value of my colors were 0, so it worked, but the text was invisible :(

Again, thanks :)

Comment
Add comment · 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

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.

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

Access custom style from skin via string 1 Answer

GUI works fine in editor, but not in build 2 Answers

GUIStyle returning error (error inside) 1 Answer

Optimizing OnGUI - Too many gui elements? 2 Answers

Changing OnGUI Texture to be behind another (GUI Rendered off of same script, different instance) 2 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