Tile mouseover highlight

Couldn’t help myself and added a highlight to the tiles you mouse over and give some visual feedback on which ones you can “build”.
ezgif.com-video-to-gif
Probably jumped the gun a bit since I wouldn’t be surprised if this is something we’d add later in a course anyway. Here is a code snip for anyone interested though:

Code
public class TileWaypoint : MonoBehaviour
{
    [SerializeField] bool isPlacable = false;

    MeshRenderer tileMeshRenderer;

    void Start() 
    {
        tileMeshRenderer = GetComponentInChildren<MeshRenderer>();
    }

    void OnMouseOver() 
    {
        if (isPlacable)
        {
            setTileColor(2f,2f,2f,1f);
        }
        else
        {
            setTileColor(3f,1f,1f,1f);
        }     
    }

    void OnMouseExit() 
    {
        setTileColor(1f,1f,1f,1f);
    }

    void OnMouseDown() 
    {
        Debug.Log(transform.name);
    }

    void setTileColor(float red, float green, float blue, float alpha)
    {
        Color tileColor = tileMeshRenderer.material.color;
        tileColor = new Color(red,green,blue,alpha);
        tileMeshRenderer.material.color = tileColor;
    }
}
3 Likes

You’ve been working through this course pretty fast, interesting idea here, it gives me a cursor affordance feel to the game, nicely done, im intruiged to see the finished game!

1 Like

I’ve actually stagnated for like a week… I spent too much time procrastinating in the community section and too little actually going through the lectures. Just managed to get myself back on track.

2 Likes

That’s great, I happened to have the same issue, nowadays I just try to have an even balance, took me a half a year to make project boost thats how bad it was, luckily I now try to prioritize a solid hour or two to pure learning, glad you also got back on track.

Privacy & Terms