- Home /
Some questions about the Tilemap API
Hello! I've been struggling with tiles in unity 2D for some time and I can't figure out how some basic things work... Supposing I have a very simple Grid object containing a Tilemap, like in this picture:
How exactly are the tiles stored inside this Tilemap object (they are stored in there, right?)? Are they stored as a 2D matrix? If yes, then where in the world is tile[0][0] placed? Also, how can I get the width/height of this matrix thing? I noticed I can get a tile by using a Vector3Int, but I could not figure out on my own how it all works.
I would want to iterate through all the tiles, left to right, top to bottom. For each tile, I would want to swap it with another tile if the tile is of a certain type. I noticed these are by default BaseTiles. So how exactly can I check if a tile is a grass tile and swap it with a water tile?
Thanks for reading so far! Any help is welcome!
Answer by mrudnicki · Oct 04, 2018 at 07:12 PM
Hi, for 1) check https://gamedev.stackexchange.com/questions/150917/how-to-get-all-tiles-from-a-tilemap
for 2) http://www.echception.com/post/tilemaps-in-unity-2017.2-part2/ here are described different approaches to tiles and its sprites and the final one is to display a different sprite in the tile based on logic.
I hope it can be helpful, currently my tilemap's knowledge is not wide enough to go deeper:)