- Home /
MouseOver Clarification Please
I've read several of the questions on this site pertaining to making 3D objects glow, highlight, etc when the player moves the mouse over them, and the example scripts provided appear to be what I'm looking for, or close to it. My question is this: I have a 3D neon sign on my title screen, created in 3DS Max, that I want to light up when moused over. It wasn't created using Unity's GUI tool (would it be easier or harder that way, considering it's a prefab currently?) I've tried attaching the script mentioned several times when explaining how to use the OnMouseOver or OnMouseEnter script, but I get an error saying that I don't have a renderer attached with which to render a new color to my neon sign.
Long story short, does anyone know what the best way to go about scripting this sign to light up realistically when the player mouses over it would be? I'm not unfamiliar with Unityscript, and I have seen all the tutorials, I think this is just a matter of a few different mental dots I need to have connected for me by devs who are more experienced. I'd really appreciate the help.
(Edit) The script I've been trying hardest with is:
var initialColor : Color;
function Start()
{
initialColor = renderer.material.color;
}
function OnMouseOver()
{
renderer.material.color = Color.red;
}
function OnMouseExit()
{
renderer.material.color = initialColor;
}
[Here is the link][1] to the question I found that script in. Although it's informative when I think about how it should work, the error I get is:
You probably need to add a Renderer to the game object "NeonSign". Or your script needs to check if the component is attached before using it. glowNeon.Start () (at Assets/glowNeon.js:5) The error message is clear enough, I need to add a renderer to my GameObject. But I suppose this is where my experience level tapers a little. Are there multiple types of renderers? Which one do I need? (Edit) Here's the hierarchy and inspector panel from my project. ![alt text][2]MissingComponentException: There is no 'Renderer' attached to the "NeonSign" game object, but a script is trying to access it.
![alt text][3] I added an experimental cube next to my neon sign, and attached the same script I used to animate the neon glow, and it works exactly the way it should. I edited a couple lines, to allow me to specify the initial color as well as the color it turns when the mouse hovers of the the object. It works perfectly on the cube, but still has no effect on the neon sign. It stands to reason that it's something with the sign mesh, or the renderer, or something, since the script works. I'm totally at a loss with this thing. [1]: http://answers.unity3d.com/questions/27938/change-the-colour-of-the-object-when-mouse-is-over.html [2]: /storage/temp/4230-hierarchy.jpg [3]: /storage/temp/4231-inspectorwindow.jpg
Can you edit your question and add a reference to the script you are trying to use?
Sure. I added a bit, let me know if there's anything else you need.
I think your script is on the wrong object - you need this script attached to the actual Neon Sign mesh object.
So, I tried attaching the script to the prefab of the sign and running, and then removing it from the prefab, attaching it to the actual instance of the sign in the game and running, and both times it gave me the $$anonymous$$issingComponentException error about the renderer missing. Is my object itself wrong somehow? It's an FBX I exported from 3DS $$anonymous$$ax into my assets... I appreciate your help. If you think of anything else I'll be at this for awhile longer.
So if you look at your object in the hierarchy and click the root object and then the children in turn - the inspector will show you which one has a $$anonymous$$esh Renderer attached - that's the one.
Answer by FWCorey · Oct 09, 2012 at 04:07 PM
A “renderer” is what makes an object appear on the screen. The GameObject in your scene with your script attached must be the same one that your “Mesh Renderer” with the model of your neon sign is attached to so your script can find it. That's why you are getting that error... it looks for the renderer on the same object as the script and can't find it. You can also assign a new variable to hold the GameObject and set it in the Inspector if you can't place both items on the same Object because of another dependency in your script.
It has a renderer on it, but I had to manually add it... it wasn't initially listed as a component of my neon sign object. The sign appeared on the screen even before I added that renderer, though... Do imported FBX objects have some kind of hidden renderer included with them? Regardless, the effect I'm going for isn't achieved regardless of whether I add the renderer or not.
Answer by static_cat · Oct 18, 2012 at 02:24 AM
Totally figured out what it was. I made the neon sign in 3DS Max using its version of the 3D Text tool, which created a tube-shaped mesh that formed the letters I typed in a neon-sign-esque font. However, it had a pretty high poly count. When Unity imported the .fbx file, it split the mesh into two meshes that it treated like one mesh, as you see in the Hierarchy box above. I spent awhile wondering why it wouldn't automatically apply the renderer to my mesh when I imported it to my scene, when it dawned on me, it had TWO renderers, one for each of the sub-objects that made up the whole mesh. So I applied the glow script I'd been using on the entire object, but instead on the two sub-objects by themselves, along with a box modifier, and viola. Thanks to FWCorey for illustrating the way renderers work, it took it some time to simmer in my head but ultimately it dawned on me what was happening, and I now have an awesome interactive neon sign.
Your answer
Follow this Question
Related Questions
make an object glow when mouse over 3 Answers
The OnMouseOver and OnMouseEnter functions cease to work when screen.lockcursor = true 0 Answers
Prevent raycast to OnMouseOver() or OnMouseEnter() when mouse over UI 1 Answer
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
How to check if mouse position is near position of a Vector3 on screen ? 0 Answers