Skip to content

The grid is not aligned after being imported into unity #269

Open
@173198205

Description

@173198205

One feature I want to implement is that when you click on a tile, you can know which tile you clicked on and show a selected status in the center of that tile. But I found that the grid is not aligned with unity's tilemap grid, causing a misalignment. What should I do? My test code:

if (Input.GetMouseButtonDown(0))
{
Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var cellPos = Tilemap.WorldToCell(pos);
var tile = Tilemap.GetTile(cellPos);
if (tile != null)
{
var wPos = Tilemap.CellToWorld(cellPos);
select.gameObject.transform.position = wPos;
Debug.Log($"click tile:{tile.name}-{cellPos}");
}
Debug.Log("GetMouseButtonDown");
}

Snipaste_2024-05-13_18-12-23
Snipaste_2024-05-13_18-11-27
Snipaste_2024-05-13_18-12-51
Snipaste_2024-05-13_18-13-25

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions