BrookDaCow
BrookDaCow

Reputation: 115

Why won't script work on 3d text? (Unity5)

So this is my code:

function OnMouseEnter()
{
    GetComponent(Renderer).material.color = Color.grey;
}
function OnMouseExit()
{
    GetComponent(Renderer).material.color = Color.white;
}

When I assign this to a regular game object like a cube it works fine, changing to grey when I hover over it with my mouse and changing to white when I take it away. But when I try this with 3d text nothing happens no matter what I do. What am I doing wrong, and how do I fix this?

Upvotes: 1

Views: 42

Answers (1)

Yuri Nudelman
Yuri Nudelman

Reputation: 2943

OnMouseEnter and OnMouseExit requires Collider attached to the object in order to work (since it uses raycasting). Game objects such as cube come with collider attached by default, 3D text doesn't. Simply attach some Collider to your text (from Inspector window: Add Component => Box Collider), then it should work.

Upvotes: 1

Related Questions