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 Mahtrok · Dec 14, 2012 at 10:08 PM · inventorygui.buttontooltipguicontent

GUI.tooltip is not set when hovering dynamic created buttons

Like many other people before and after me i'm working on a RPG inventory and i got some problems with getting a tooltip when hovering over the different Items.

Everything works fine but the tooltip...

I tried nearly any of the ideas i found in unityAnswers and inside some unity community forums.

I'm coding in c# so for now i use a new GUIContent(string, string) to set the tooltip and yes, that works perfectly on few buttons i specified exactly, each by its own rect and throws it out on Debug, boxes, labels aso.

But in my inventory i don't want to define every single button so i'm using a for loop running through lines and rows, creating all buttons. I guess somehow the tooltip information is not set or changes to fast to be shown inside this loop.

Anyone got any other idea on how to get this done?

     /// <summary>
     /// Dos the bag window.
     /// </summary>
     /// <param name='_id'>
     /// _id.
     /// </param>
     void DoBagWindow (int _id) {
         int _fieldCount = 0;
         string _itemDescr = string.Empty;
         Rect _fieldRect = new Rect(0,0,0,0);
         Texture2D _tempTex = _defaultTexture;
         
         BaseItem _tempItem = null;
         
         if(GUI.Button(new Rect(_screenHeight-25, 5, 20,20), "X", healthtext)){
             _selectedWindow = 100;
         }        
         GUI.BeginGroup(new Rect(10, 10, 300, 300), string.Empty);
 
         for(int _lines = 0; _lines < 7; _lines++){
             for(int _rows = 0; _rows < 7; _rows++){
                 _fieldCount++;
                 _fieldRect = new Rect(_rows*40, 10+_lines*40, 40, 40);
                 if(_inventory.INVENTORYSIZE > _fieldCount){
                     _tempItem = _inventory.GetItemAtSlot(_fieldCount);
                     
                     if(_tempItem != null){
                         _tempTex = _tempItem.APPEARENCE;
                         _itemDescr = _tempItem.DESCRIPTION;
                     }
                     else{
                         _tempTex = _defaultTexture;
                     }
                 }
                 if(GUI.Button(_fieldRect, new GUIContent(_tempTex, _itemDescr))){
                     if(_tempItem != null)
                         Debug.Log("Clicked " + _tempItem.NAME);
                     else
                         Debug.Log("Clicked an empty Slot");
                 }
             }
         }
         GUI.EndGroup();        
     }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mahtrok · Dec 17, 2012 at 02:13 PM

Ok, sometimes its really the best just to leave it alone for a few hours of sleep.

If i do set the tooltip during one loop, the program simply sets another bool true to remember that i found a button with event.current.mouseposition in it. if this bool is false i reset the tooltip, if true tooltip is displayed.

      for(int _lines = 0; _lines < 7; _lines++){
          for(int _rows = 0; _rows < 7; _rows++){
           _fieldCount++;
           _fieldRect = new Rect(_rows*40, 10+_lines*40, 40, 40);
           if(_inventory.INVENTORYSIZE > _fieldCount){
               _tempItem = _inventory.GetItemAtSlot(_fieldCount);
 
               if(_tempItem != null){
                  _found = true;
                  _tempTex = _tempItem.APPEARENCE;
                  _itemDescr = _tempItem.DESCRIPTION;
               }
           }
           if(GUI.Button(_fieldRect, new GUIContent(_tempTex, _itemDescr))){
               if(_tempItem != null)
                  Debug.Log("Clicked " + _tempItem.NAME);
               else
                  Debug.Log("Clicked an empty Slot");
           }
          }
        }
 if(!_found){
    _tempTex = _defaultTexture;
    _itemDescr = string.Empty;
 }
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

9 People are following this question.

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

Related Questions

Display images in tool tips and buttons 1 Answer

tooltip to show from array C# 1 Answer

How to add multiple lines of text in GUI.Button with different font styles? 0 Answers

display hints while mouse is over a text field using tooltip 3 Answers

New UI Is active but not drawing 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