On mouse Enter

I’m trying to make a RTS. Like in almost eer RTS you can select your units and they turn a different color and show information about them. I’ve made a basic function witch makes the material change to a different color when you move your mouse over the object. But when I remove the mouse form the object the material stay’s the same. I would like it to go back to its default state after i remove the mouse. I think i would have to keep the default material in a variable and use the OnMouseExit function but i don’t know how. Can someone please help. Thanks in advance.

1 Answer

1

Declare two Materials on top of your script

private var defaultMaterial : Material;
var onHoverMaterial : Material;

When the mouse enter, save the current mat and set it to onHover

function OnMouseEnter(){
    defaultMaterial = renderer.material;
    renderer.material = onHoverMaterial;
}

Reverse when exit

function OnMouseExit(){
    renderer.material = defaultMaterial ;
}