Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 andresp · Sep 20, 2011 at 02:33 PM · guicolorguilayoutboxonhover

Text color change onHover

Hi,

I'm trying to change the text color of a GUILayout.Box using the onHover text color of my skin but, for some reason, it isn't working at all.

GUILayout.Box("text", GUI.skin.GetStyle("custom_style"));

Do you know how can I do this?

Thanks in advance, André

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by jahroy · Sep 20, 2011 at 04:51 PM

Your code suggests that you've added a custom style named "custom_style" to a GUISkin that has been assigned in your game.

You need to assign your GUISkin in the OnGUI function, which looks something like this:

var myCustomSkin : GUISkin;

function OnGUI() { GUI.skin = myCustomSkin; }

Also, onHover only applies to toggle buttons that are in their "on" state. You want to use hover in stead.

Also, if you don't have a background image associated with the hover state, it won't work.

The states that don't have background images are ignored.

Comment
Add comment · Show 3 · 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 andresp · Sep 20, 2011 at 05:21 PM 1
Share

thanks jahroy.

I had already done that assignment, however I didn't know that onHover only works with Toggle. On GUILayout.Label documentation it is written:

"Labels have no user interaction, do not catch mouse clicks and are always rendered in normal style. If you want to make a control that responds visually to user input, use a Box control"

http://unity3d.com/support/documentation/ScriptReference/GUILayout.Label.html

that's why I was expecting that a Box would handle onHover events.

Regarding the background images limitation, is the use of a transparent png a valid workaround?

avatar image jahroy · Sep 20, 2011 at 06:20 PM 0
Share

I remember experiencing similar expectations!

That sounds like a perfect workaround to me.

You could make it a 1 pixel image if you like.

avatar image Canadian Hobo · Apr 29, 2013 at 03:27 AM 0
Share

You could use a transparent PNG as the background image as well.

avatar image
0

Answer by Ray-Pendergraph · Sep 20, 2011 at 04:27 PM

You can set the textcolor on the GUIStyleState for the appropriate mode(s) that you need it for (probably onHover in your case). You can do this through the inspector or code.

Comment
Add comment · Show 1 · 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 DrDecipher · Aug 15, 2014 at 02:27 AM 0
Share

HERE YA GO!

http://forum.unity3d.com/threads/gui-button-hover-change-text-color-solved.262440/

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

How to render a colored 2D rectangle. 6 Answers

Change color of Gui.Box background to solid black 1 Answer

How can i change the color of GUILayout elements? such as buttons 1 Answer

Why can't I get my tooltip to show only when there is a tooltip set? 2 Answers

Changing two different objects renderer colour 1 Answer


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