Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by Surfer · May 08, 2010 at 08:11 PM · javascriptguitextmouse

How can I display text and change color of objects when I roll over them with the mouse?

Hi I am new to Unity3D and don't know how to solve this problem. I am making a product demo and where you can rotate the product and explain what different parts do.

On one side of the screen will be a vertical list of parts e.g. 1.Nut 2.Washer 3.Case 4.Switch etc. 5... In the center of screen will be the product which can be rotated in 3D. At the Bottom of screen will be a text filed explaining what each part does.

What I need help to do is make the Parts list interactive.

That is to say when I put the cursor over the name of each part i.e. 1.Nut the text changes color (highlights) at the same time the 3D part (mesh) changes color and also text explaining the function of the part appears at the bottom of the screen. The camera and 3D model are not a problem I just need make interactive parts list work. If anybody can help I would really appreciate it. I am using Java script.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by duck · May 08, 2010 at 10:46 PM

First, make sure that you add a collider component to each part which you want to be an active rollover.

Next, add a GUI Texture GameObject to your scene (from the GameObject menu). Rename it to "Rollover Text Display" (exactly, case sensitive).

Now create a new Javascript script, name it "RolloverItem", and paste this in:

var rolloverText = ""; var rolloverColor = Color.red; private var originalColor : Color; private var textDisplay : GUIText;

function Start() { originalColor = renderer.material.color; if (rolloverText == "") { rolloverText = gameObject.name; } textDisplay = GameObject.Find("Rollover Text Display").guiText; }

function OnMouseEnter() { Debug.Log(textDisplay.gameObject.name); textDisplay.text = rolloverText; }

function OnMouseExit() { Debug.Log(textDisplay.gameObject.name); textDisplay.text = ""; }

Finally, add this script to each object that should have rollover text. If you don't specify some text in the "Rollover Text" field for each item, the object's name will be displayed. You can so adjust the rollover colour.

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 Surfer · May 09, 2010 at 10:24 AM 0
Share

Thanks for your help that script put text on screen when the mouse rolls over a 3D object which is very useful to know, but not 100% what I am looking for. To help explain what I need here is quick 2D mock-up in flash.

http://www.siamation.com/FunctionTest.html I would like to do something like this in 3D. Notice only the parts list on the left is interactive, that's because some parts are hidden by other parts so impossible make roll overs. But they to change color and text explaining what they do appears on the bottom of the screen.

Thanks

avatar image Surfer · May 09, 2010 at 02:57 PM 0
Share

O$$anonymous$$ i got it partly working using a GUItexture but had to remove this line of code

originalColor = renderer.material.color;

Now all I have to do is some how reference the object to change its material color.

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

Setting Scroll View Width GUILayout 1 Answer

What's wrong with my function? It keeps telling me 'loseText' is not a member of 'UnityEngine.GUIText'. Please help, please and thank you! 0 Answers

Changing 3d text through script 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Limit on GUI Components? 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