- Home /
Question by
karajohnnies · Nov 10, 2020 at 02:22 PM ·
tilemaptiletiles
Get tile coordinates
So i want to find specific tiles in a tilemap (a grass tile) and spawn a tree on each one. I managed to store all those tiles in an array but how can i retrieve each tile coordinates in order to pass them to instantiate in order to spawn a tree on top of it? for example.
public BoundsInt area;
public Tilemap grass;
public Tile grassTile;
public GameObject tree;
TileBase[] tileArray = grass.GetTilesBlock(area);
for (int index = 0; index < tileArray.Length; index++)
{
if (tileArray[index]== grassTile) {
Instantiate(tree, "GET COORD/POSITION OF THE TILE" ,Quaternion.identity);
}
}
Comment
Best Answer
Answer by karajohnnies · Nov 10, 2020 at 07:08 PM
Solved
foreach (Vector3Int position in grass.cellBounds.allPositionsWithin)
{
if (grass.GetTile(position) == grassTile)
{
Vector3 cellPosition = grass.GetCellCenterWorld(position);
Instantiate(tree, cellPosition, Quaternion.identity);
}
}
Your answer
Follow this Question
Related Questions
Remove a single tile from a tilemap 1 Answer
Having trouble with dragging sprites into the tile palette 1 Answer
I can‘t assign a folder to my tile palette,I cannot assign a folder to my tile palette 0 Answers
Tilemaps making feature 1 Answer
Can you add sprites to existing sprite sheet without breaking the tile pallet and in-game tiles 0 Answers