- Home /
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.
Answer by Berenger · Mar 25, 2012 at 04:24 AM
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 ;
}
Your answer
Follow this Question
Related Questions
Selecting gameobjects in game, 3 Answers
need advice about making object to stand out 0 Answers
Display Press E to Pickup when mouse over object 2 Answers
Create terrain with grid 0 Answers
Highlighting parts of an object 1 Answer