Why won't script work on 3d text? (menu script)
So here 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 assigning this to 3d text nothing happens no matter what I do. What am I doing wrong, and how do I fix this?
Answer by OncaLupe · Dec 17, 2015 at 10:03 AM
OnMouseEnter()/OnMouseExit() requires a Collider attached to the object. Testing in Unity 5.3 shows adding a BoxCollider2D works fine for me.
If you're making a 2D game you can assign it to a new Layer and use the Physics2D player settings to have it ignore collisions to all other layers. That way it won't collide with objects in the game. If making a 3D game there's no worries as 3D physics doesn't interact with the 2D physics.
Your answer
Follow this Question
Related Questions
Scrpits component disappears when I enter playmode 0 Answers
Can I Reference Object Components from another Scene? 0 Answers
how to get a component from another script and affect the changes on it as well 0 Answers
If several BoxCollider attach to a gameObject, how to differ them? 0 Answers
Trigger enabling component works in one statement but not another? 1 Answer