- Home /
How do I make one object appear when I mouse over another object?
I am currently working on a menu, and I would like for another object in the scene to appear when I mouse over my 3D text.
The object in question is currently set to invisible using this script:
GetComponent(MeshRenderer).enabled = false;
My understanding is that if I set the value above to True, it will do the trick.
However,
Which object should I put that part of the script on?
And where in that script do I identify the object that I want to make visible?
Thank you.
Answer by MikeNewall · Feb 21, 2014 at 12:20 AM
Attach this script to your text. Assign the object you want to show to the menuObject variable in the inspector.
public GameObject menuObject;
void Start(){
menuObject.renderer.enabled = false;
}
void OnMouseOver(){
menuObject.renderer.enabled = true;
}
Just so you know a Gameobject has a property which gets its renderer if it has one attached so you don't need to get the component :)
Thank you for the reply! I did get an error upon attaching that script to the 3D text object:
Assets/invisibleVisible.js(3,12): BCE0043: Unexpected token: GameObject.
@al468155 - the above script is C#. You pasted it into a Javascript file.
@$$anonymous$$ikeNewall and @robertbu, thank you both very much! I got it working right away! Perfect!!
Ins$$anonymous$$d of posting a follow up/thank you as another ANSWER (as you did here), please tick the 'Accept Answer' icon under the thumbs icons up there. I converted this one for you.
Your answer
Follow this Question
Related Questions
Converting C# to JS: rendering a mesh 1 Answer
Mouse over make object Visible 2 Answers
Invisible objects renderer disable? How to stop this? 0 Answers
Gui Menu - Help Please. 2 Answers
get object invisible for couple seconds and get visible again 1 Answer