I’ve got one tilemap for walls, and one for floors, both under the same grid. What I’m trying to do is put a script onto a tilemap and have it spawn enemies randomly on that tilemap, like random spawning in Earthbound.
The problem is, I don’t know how to get the position of a specific tile. I was trying to use:
public TileMap tileMap;
foreach (Tile tile in tileMap.GetTilesBlock(tileMap.cellBounds))
{ // convert matrix4x4 to vector3 and add to list }
but for some reason, when I Debug.Log the transform of ‘tile’, it shows the current amount of tiles, and if I use an if statement it can tell me how many are null, but the transform is always the same, and doesn’t seem to change depending on which tile it’s currently processing.
Also it’s a matrix4x4 which I have no experience with at all, and there’s not much documentation so I’m probably not even going about this in the right way. Any help figuring out how to get a list of all used tile positions, or a clever workaround would be much appreciated.
Thanks for the reply! It wasn’t exactly what I was looking for, but my code was a lost cause. I think I was trying to get the position of a tile from the tile prefab… But now I’ve fixed my code up a bit, and using CellToWorld does do exactly what I need it to!
I’m trying a similar thing I’m using tile maps with specific sprites of enemies as spawning locations for the real enemies to be created at. But I can’t find a way to get the position of the specific tiles.
I know that the position is used in some functions as GetTilesBlock(boundsInt) wouldn’t be functional if it couldn’t detect the position of a tile to know its within the bounds.