- Home /
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
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.
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
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
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
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