Open 173198205 opened 4 months ago
Then I tested the click myself with a ray
Hi there, @173198205. Sorry I'm getting back to you so late.
I think this is an error with Super Tiled2Unity where I'm not taking into account the different coordinate systems between Tiled and Unity. Normally you wouldn't notice but if you're trying to click on a tile I can see that being a problem.
Can you test something out for me? Try changing your Tilemap
component so that you have a Custom
orientation and offset the tilemap by half of your tile width (64 in your case, I think). That's not a real fix but it should help me track down what I need to do.
Would it possible for me to look at your project? I'd like to make sure the fix I come up actually works for you. Thanks.
I am a novice and do not understand many things, the project is just a simple test that can show you. It doesn't seem to work if you change the offset as you said. I later thought of a way to implement it, that is, to abandon the idea of tilemap, convert the map into an object, and use rays and colliders to detect clicks, which I basically realized. project2021.zip
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"); }