OnMouseOver not continous?

Hi there,

I got a question about OnMouseOver, OnMouseDown and OnMouseExit. The documentation doesn’t solve my problem. I have an object with a collider and when I move the mouse over it, I want it to glow. The effect should stop if i move my mouse away from the object of course. It’s working pretty good with the following script i wrote:

var factor : Color ; 

function OnMouseOver () {
renderer.material.SetColor("_Emission", factor);
}

function OnMouseExit () {
renderer.material.SetColor("_Emission", Color.black);
}

Here is the problem: When I hover over the objects, it glows. If I leave the object it recieves it’s old color back. But when I hover over the object and click with the mouse, it stops glowing, until I move the mouse at least 1 pixel. Then it glows again perfectly. How can I fix that?

Greetings,
Thoro

First of all, why are you using OnMouseOver()? I’d go for OnMouseEnter(), which will only be called once and not continuous.

As to your question, it seems when OnMouseDown() is called OnMouseExit() is called as well. You could stop it from being run by wrapping what you have inside your function inside an

if( !input.GetMouseButton( 0 ) ){
   renderer.material.SetColor("_Emission", Color.black);
   } 

see if that does the trick. Strange that OnMouseExit() is being called when you click though