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 austinj · Jan 17, 2011 at 08:44 PM · guitextonmouseover

GUI OnMouseEnter popup. text String is layering for multiple game objects?

Hello Everyone,

Sorry if that title is a little confusing.

I am trying to create a script that I can attach to multiple gameobjects in a scene, which will, when the mouse is hovered over them, make the game object change colors and create a GUI label with some game object specific text. This works just fine for one gameobject, but when I add the script to multiple game objects and assign them different text, when I mouse over them, it is layering all the different lines of text on top of each other in the GUIlabel. So, if I have two object and the text reads "Cube 1" and "Cube 2", when I mouse over one, it renders both labels on top off each other.

Hope that makes at least a little sense. Thanks in advance for any help. I am sure this is something simple that I am just not looking at.

Also, I am a total programming noob, so take it easy on me :)

Here is the script...

var mySkin : GUISkin; var text : String; static var isHovering = false;

function OnMouseEnter(){ renderer.material.color = Color.green; isHovering = true; } function OnMouseExit(){ renderer.material.color = Color.white; isHovering = false; } function OnGUI(){ GUI.skin = mySkin; if(isHovering){ GUI.Label (Rect(400,300,180,60), text); } }

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

Answer by Eric5h5 · Jan 17, 2011 at 09:18 PM

When a variable is static, that means only one instance of it can ever exist. So when isHovering is true for one script, it's true for them all. Basically you shouldn't use static variables unless you actually mean for it to have one instance.

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 austinj · Jan 18, 2011 at 12:54 PM 0
Share

Hah! I didnt know that but it makes perfect sense. I was really only using the static variable so I didnt have to look at the check box in the editor...
Thanks so much for the help and the quick response!

avatar image Eric5h5 · Jan 18, 2011 at 05:40 PM 0
Share

@austinj: use private variables if you don't want to see them in the editor. You can also use @HideInInspector for public variables.

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

Text appear on screen when I stand over object. 1 Answer

How can I add "..." to GUI.Label if it goes past its bounds? 1 Answer

Checking 2 string variables 0 Answers

How to make text that scrolls horizontally? 2 Answers

OnGUI called after LateUpdate screwing up debug text database 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