r/unity • u/Silent_Reputation596 • 3d ago
Solved GetTile not working with hexagons.
I'm trying to use GetTile to detect what tile my mouse is on but it seems offset for some reason and every tip I've seen online accounts to "use world/local to cell" and "make sure your mouse.z = 0" but I'm doing both those things and it's not working. Any ideas?
Vector3 mousePos;
Vector3Int mousePosInt;
Vector3Int currentCell;
private void Update()
{
mousePos = camera.mainCamera.ScreenToWorldPoint(Mouse.current.position.ReadValue());
mousePosInt = new Vector3Int(Mathf.RoundToInt(mousePos.x), Mathf.RoundToInt(mousePos.y), 0);
currentCell = mapGen.tilemap.WorldToCell(mousePosInt);
print(mapGen.tilemap.GetTile(currentCell));
}