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
1
Question by Art 1 · Jan 27, 2011 at 05:29 AM · guigameobjectmousehovertooltip

Tooltip when mousing over a game object?

I need to have like a tooltip that appears over some objects in my scene when they hover the mouse over them. Is this possible? I see the tuts for doing GUI elements, but these are 3D things. Help!

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

Answer by DaveA · Jan 27, 2011 at 05:34 AM

This is what I use:

var toolTipText = ""; // set this in the Inspector

private var currentToolTipText = ""; private var guiStyleFore : GUIStyle; private var guiStyleBack : GUIStyle;

function Start() { guiStyleFore = new GUIStyle(); guiStyleFore.normal.textColor = Color.white;
guiStyleFore.alignment = TextAnchor.UpperCenter ; guiStyleFore.wordWrap = true; guiStyleBack = new GUIStyle(); guiStyleBack.normal.textColor = Color.black;
guiStyleBack.alignment = TextAnchor.UpperCenter ; guiStyleBack.wordWrap = true; }

function OnMouseEnter () {

 currentToolTipText = toolTipText;

}

function OnMouseExit () { currentToolTipText = ""; }

function OnGUI() { if (currentToolTipText != "") { var x = Event.current.mousePosition.x; var y = Event.current.mousePosition.y; GUI.Label (Rect (x-149,y+21,300,60), currentToolTipText, guiStyleBack); GUI.Label (Rect (x-150,y+20,300,60), currentToolTipText, guiStyleFore); } }

Make sure you have a collider on your object and IsTrigger is set. This will make a white-with-black-dropshadow label, no background, that floats around with your mouse pointer.

Comment
Add comment · Show 7 · 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 Art 1 · Jan 27, 2011 at 05:39 AM 0
Share

Cool thanks. Can I have a solid background, maybe semi-transparent?

avatar image ess · Jun 21, 2012 at 07:05 PM 0
Share
  • for this reply. Perfect solution to my problems! Thank you!

avatar image zachnamyat · Aug 06, 2012 at 12:43 AM 0
Share

This was the most helpful script ever. Thanks!

avatar image srmojuze · Apr 03, 2013 at 07:55 AM 0
Share

Thanks, and, to "Highlight" the object on mouse over, use renderer.material.color or something similar, then change it back on mouse exit. Conversely you can "fade" all the ~other~ objects by iterating through them and setting alpha part of Color to less than 1.

avatar image xlaser · Jun 01, 2013 at 05:02 AM 0
Share

Cool Code ! but how to display multi line text ?

Show more comments

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

7 People are following this question.

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

Related Questions

Detecting Mouse Over Using Tooltip 2 Answers

GUI.Button on MouseHover 1 Answer

GUI texture updating in preview but not in game 1 Answer

Handling mouse events in objects inside a trigger? 0 Answers

GUI texture to change texture when hovered over or clicked? 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