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 DMCH · Apr 20, 2013 at 04:33 PM · c#guibutton

Setting tooltip text depending on condition

Hello,

Wondering if anyone can help me solve a problem concerning tooltips. I have a character screen and a tooltip at the bottom of the screen to explain the label/button the player has the mouse over. This is working fine, but I'd like to have the text change depending on certain conditions present in the scene.

Example

 // Speed + Button
 if(GUI.Button(new Rect(x, y, a, b), new GUIContent("", "Increases Character Speed"), "StatButton")
 {
     // Condition satisfied
     if(freeAttributePoints > 0)
     {
         // No need to show a message, just leave the button GUI content
     }
     
     // Condition not satisfied
     else
     {
         // Show a different message on tooltip, i.e. No free attribute points
     }
 }

How I'm declaring tooltip:

 // ToolTip Label
 GUI.Label(new Rect(0, tooltipYPos, tooltipWidth, tooltipHeight), GUI.tooltip, "ToolTip");


Thanks for reading!

Comment
Add comment · Show 1
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 DMCH · Apr 20, 2013 at 06:46 PM 0
Share

Following Ricardo's suggestion, I was able to solve the issue. I drew a second label (alt tool tip) over the tooltip, and only had it display when a bool was true. Then, when the button was pressed, I loaded in the string to be displayed by the alt tooltip, and set the boolean to draw over the original tooltip to true. A timer was used to reset the boolean, and allow the original tooltip to be seen.

1 Reply

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

Answer by ricardo_arango · Apr 20, 2013 at 04:58 PM

You could make the tooltip text a variable:

string tooltip = "Increases Character Speed";

then when the button is clicked and the condition is met, replace it with a different value:

tooltip = "a different message on tooltip";

You would display your button like this:

 // Speed + Button
 if (GUI.Button(new Rect(x, y, a, b), new GUIContent("", tooltip), "StatButton"))
 {
     // Condition satisfied
     if (freeAttributePoints > 0)
     {
         // No need to show a message, just leave the button GUI content
     }
 
     // Condition not satisfied
     else
     {
         // Show a different message on tooltip, i.e. No free attribute points
         tooltip = "a different message on tooltip";
     }
 }
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 DMCH · Apr 20, 2013 at 05:46 PM 0
Share

Thanks Ricardo. $$anonymous$$inda get the idea, but it's not quite working yet, the different message in the else block isn't showing. The "Increase character speed" keeps showing. Guessing the else block tooltip string is being overwritten by string tooltip = "Increase Character Speed". Any ideas?

 string tooltip = "Increase Character Speed"; 
             
 // Speed + Button
 if(GUI.Button(new Rect(x, y, a, b), new GUIContent("", tooltip), "StatButton")
 {
     // Condition satisfied
     if(freeAttributePoints > 0)
     {
         // No need to show a message, just leave the button GUI content
     }
     
     // Condition not satisfied
     else
     {
         // Show a different message on tooltip, i.e. No free attribute points
         tooltip = "No free stat points";
     }
 }
avatar image ricardo_arango ♦♦ · Apr 20, 2013 at 08:53 PM 0
Share

You need to define the "tooltip" variable outside of the OnGUI function, as part of the class. Otherwise it is initialized every frame.

avatar image DMCH · Apr 21, 2013 at 12:04 AM 0
Share

Ah yes, careless of me. Thanks Ricardo.

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

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How Do You Use GUIText to Move Through Multiple Texts? 1 Answer

Help with C# coding a loaded button (3.x Game Development Essentials) 1 Answer

How to trigger button press on a button in an editor window by pressing the return key ? 0 Answers

In game Escape menu displays all the time 1 Answer

How to make a box appear after pressing a button? 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