x


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

more ▼

asked May 08 '10 at 08:11 PM

Surfer gravatar image

Surfer
21 1 1 2

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered May 08 '10 at 10:46 PM

duck gravatar image

duck ♦♦
41.4k 95 152 415

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

May 09 '10 at 10:24 AM Surfer

OK 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.

May 09 '10 at 02:57 PM Surfer
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5272
x3812
x3570
x1001
x567

asked: May 08 '10 at 08:11 PM

Seen: 6043 times

Last Updated: May 08 '10 at 10:47 PM