Hi,
I have encountered a bug I don’t understand.
I’m trying to highlight a tile when the mouse is over it on a hexagonal grid.
Here is the script i’m using :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
public class GridController : MonoBehaviour
{
private Grid grid;
[SerializeField] private Tilemap interactiveMap = null;
[SerializeField] private Tile hoverTile = null;
private Vector3Int previousMousePos = new Vector3Int();
// Start is called before the first frame update
void Start()
{
grid = gameObject.GetComponent<Grid>();
}
// Update is called once per frame
void Update()
{
// Mouse over -> highlight tile
Vector3Int mousePos = GetMousePosition();
if (mousePos != previousMousePos)
{
interactiveMap.SetTile(previousMousePos, null); // Remove old hoverTile
interactiveMap.SetTile(mousePos, hoverTile);
previousMousePos = mousePos;
}
}
Vector3Int GetMousePosition()
{
Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
return grid.WorldToCell(mouseWorldPos);
}
}
I tried this with a regular tilemap and it works. So I really don’t understand why it doesn’t work with a Hexagonal Tilemap.
Anyone know where this comes from ?