I would like to make it so if the cursor enter a tile, it becomes "higlighted" (slightly whitened), like the left tile below.
I'm quite new to Unity, and after reading an article from Thomas Mountainborn (http://thomasmountainborn.com/2016/05/25/materialpropertyblocks/) I managed to do this with a simple shader on an Object, and changing a parameter in a MaterialPropertyBlock when the mouse enter or quit its collider.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Highlight: MonoBehaviour
{
[SerializeField]
private float baseHighlightFactor;
private Renderer _renderer;
private MaterialPropertyBlock _propBlock;
private float _highlight;
void Awake()
{
_propBlock = new MaterialPropertyBlock();
_renderer = GetComponent<Renderer>();
_highlight = 0;
}
private void Update()
{
// Get the current value of the material properties in the renderer.
_renderer.GetPropertyBlock(_propBlock);
// Assign our new value.
_propBlock.SetFloat("_hooverFactor", _highlight);
// Apply the edited values to the renderer.
_renderer.SetPropertyBlock(_propBlock);
}
private void OnMouseEnter()
{
_highlight = baseHighlightFactor;
}
private void OnMouseExit()
{
_highlight = 0;
}
}
I wondered if I could do the same with tiles, but with scriptable tiles I can't seem to do it, since the Renderer is a component of the Tilemap and not the Tile itself.
Am I going the wrong direction? I would not like to duplicate each sprite (highlighted/not highlighted) since I have a lot of them. I guess I could use Objects instead of Tiles, but Tilemap properties could be useful for other parts of my project.

