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 Hedgoeg · Jan 14, 2013 at 06:22 PM · javascriptonguionmouseenter

GUI text appear when mouse hovering on a object?

Hello there,
I seem to have a problem with scripting, so I hope you don't mind me asking this.
Long story short, I'm making a game. Yeah, it's simple as that. I'm not good at scripting, I don't know how to include a function in a function (OnMouseEnter + OnGui,) so excuse me.

Basically, when I hover my mouse on a object, a gameobject that exists in my game, some text appears, and when my mouse is not making out with it, the text is gone.

Is that possible? Can anyone help me with this?

Thanks.

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

Answer by RAJ_VH · Jan 15, 2013 at 07:47 PM

You can use this script:


 var text = "YOUR TEXT HERE";
 
 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 = text;
 }
 
 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+40,300,60), currentToolTipText, guiStyleBack);
         GUI.Label (Rect (x-150,y+40,300,60), currentToolTipText, guiStyleFore);
     }
 }



I found the script in the Free Basic FPS Horror Type Package by MadToLove.

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
avatar image
0

Answer by harko12 · Jan 14, 2013 at 06:59 PM

I think you might be able to do it by using a member variable for the text you want to display. When you hover on the object, you can set the member variable text to whatever you want, and then when you leave the object, it will set back to "". for instance

 var Message = "";
 
 OnGUI()
 {
  GUI.Label(new Rect(10,10,200,30),Message);
 }
 
 OnMouseEnter()
 {
  Message = "Here I am.";
 }
 
 OnMouseExit()
 {
  Message = "";
 }
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 Hedgoeg · Jan 15, 2013 at 06:28 PM 0
Share

Doesn't seem to work.

avatar image harko12 · Jan 15, 2013 at 07:50 PM 0
Share

Tough to tell why without any code to look at. You can try the example the guy posted, below, but it's essentially the same thing I posted.

avatar image MagicGeek123 · Nov 22, 2013 at 03:41 AM 0
Share

Try useing this script if you want though its more geared toward useing a texture as opposed to text (it can also be used for note type things you'll see)the note is your texture.

pragma strict

private var guiShow : boolean = false;

var note : Texture;

function On$$anonymous$$ouseEnter()//TriggerStay (Col : Collider) { //if(Col.tag == "Player") //{ guiShow = true; //} }

function On$$anonymous$$ouseExit()//TriggerExit (Col : Collider) { //if(Col.tag == "Player") //{ guiShow = false; //} }

function OnGUI() { if(guiShow == true) { GUI.DrawTexture(Rect(Screen.width / 2.25, Screen.height / 2.25, 100, 93), note); } }

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

11 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

Related Questions

Wiggle Or shake button possible? 2 Answers

OnGUI Script Not Working With Boolean... 1 Answer

OnMouseDown carry out whole function problem 0 Answers

OnMouseDown and GUI function 0 Answers

GUI opacity. 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