Search code examples
c#unity-game-enginemouseoverhighlight

How do i create a highlight of my GameObject in unity everytime the cursor is on top of it?


I'm really aiming for specific game objects to become highlighted while my mouse is over them

I've scoured the internet for a solution (or even somewhere to start) and found this. However it seems unity won't let me change the color of an object i've already set in maya? it changes in the inspector but not on the screen


Solution

  • Maybe this can help you

    This will be attached to all the things that can be higlighted with hovering.

    private Color startcolor;
     void OnMouseEnter()
     {
         startcolor = renderer.material.color;
         renderer.material.color = Color.yellow;
     }
     void OnMouseExit()
     {
         renderer.material.color = startcolor;
     }
    

    Source: Best way to "highlight" an object on mouse over