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 erenaydin · Mar 28, 2011 at 09:11 PM · gui.buttontooltip

tooltip on guibutton

i have a guibutton with texture2d

if (GUI.Button(Rect(TargetX+20,TargetY+15,55,70),Resources.Load("item/ring",Texture2D))) {
                BS_Skill = 0;}`

how can i make a tooltip when the mouse over the button. i tried with guicontent but system told me guicontent supports (string,string) not (texture2d,string)

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
1
Best Answer

Answer by Bunny83 · Mar 28, 2011 at 10:19 PM

You can use a Texure in GUIContent. Just take a look into the scripting reference.

From documentation:

static function GUIContent (image : Texture, tooltip : string) : GUIContent

Since Texture2D is derived from Texture you can assign it to image. You could add your GUIContent-version to your question, maybe there's something wrong with your syntax. You can edit your question at any time.


edit

var ringTexture : Texture2D;

function Start() { ringTexture = Resources.Load("item/ring",Texture2D); }

function OnGUI() { if (GUI.Button (Rect (10,10,100,20), GUIContent (ringTexture,"Tooltip"))) { //... } }

You could also drag and drop the texture onto the variable in the inspector. That way you don't need to place it in the resources folder and don't need to load it manually.

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 erenaydin · Mar 29, 2011 at 11:07 AM 0
Share

icon : Texture; GUI.Button (Rect (10,10,100,20), GUIContent (icon, "This is the tooltip")

is working but ;

GUI.Button (Rect (10,10,100,20), GUIContent (Resources.Load(item,Texture), "This is the tooltip") is not working ?

why

avatar image Bunny83 · Mar 29, 2011 at 12:06 PM 0
Share

That's the problem of JS and it's implicit typing. Resources.Load returns a reference of type Object. It have to be casted to the right type. In most cases it happens automatically but in this case Unity don't know to what type it should cast because there are more than one versions of the GUIContent-constructor. You even shouldn't use Resources.Load in Update (or OnFUI). Load the texture once at start and save it in a variable. I will edit my answer.

avatar image
1

Answer by Justin Warner · Mar 28, 2011 at 09:17 PM

http://unity3d.com/support/documentation/ScriptReference/GUI-tooltip.html

In case you missed it...

function OnGUI () { // Make a button using a custom GUIContent parameter to pass in the tooltip. GUI.Button (Rect (10,10,100,20), GUIContent ("Click me", "This is the tooltip"));

 // Display the tooltip from the element that has mouseover or keyboard focus
 GUI.Label (Rect (10,40,100,40), GUI.tooltip);

}

And that's an example...

http://unity3d.com/support/documentation/ScriptReference/ScriptRefImages/GUITooltip.png

Good luck!

And I edited to make the code you had coded... Just highlight your code, and then push the 10101 button, =). For future posts, and 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

No one has followed this question yet.

Related Questions

GUI.Tooltip for converted GUIStyle element 1 Answer

GUI.tooltip is not set when hovering dynamic created buttons 1 Answer

Tooltip with GUI.TextField 2 Answers

Custom Inspector tooltips behaving inconsistently 0 Answers

OnPointerExit Not Being Triggered 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