- Home /
Get position from Isometric TileMap
I really getting frustated about that, i cant get it to work... but in default TileMap(ex: topdown 2d) is working fine.
(get this code from internet)
get position and store in a dictionary:
tiles = new Dictionary<Vector3, WorldTile>();
foreach (Vector3Int pos in Tilemap.cellBounds.allPositionsWithin)
{
var localPlace = new Vector3Int(pos.x, pos.y, pos.z);
if (!Tilemap.HasTile(localPlace)) continue;
var tile = new WorldTile
{
LocalPlace = localPlace,
WorldLocation = Tilemap.CellToWorld(localPlace),
TileBase = Tilemap.GetTile(localPlace),
TilemapMember = Tilemap,
Name = localPlace.x + "," + localPlace.y,
Cost = 1 // TODO: Change this with the proper cost from ruletile
};
tiles.Add(tile.WorldLocation, tile);
}
my test, click on tile and set color to green:
private void Update () {
if (Input.GetMouseButtonDown(0))
{
Vector3 point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var worldPoint = new Vector3Int(Mathf.FloorToInt(point.x), Mathf.FloorToInt(point.y), 0);
var tiles = GameTiles.instance.tiles; // This is our Dictionary of tiles
if (tiles.TryGetValue(worldPoint, out _tile))
{
print("Tile " + _tile.Name + " costs: " + _tile.Cost);
_tile.TilemapMember.SetTileFlags(_tile.LocalPlace, TileFlags.None);
_tile.TilemapMember.SetColor(_tile.LocalPlace, Color.green);
}
}
}
but this get other tile or none... plis help
Answer by kashyapdarania · Mar 26, 2021 at 08:39 AM
Hey, Did you get any solution for this? @antoniomonteiro
Your answer
Follow this Question
Related Questions
How do I set up my sprites/skeletons to correctly interact with isometric sorting layers? 2 Answers
How to use the same tilemaps among multiple scenes (e.g. making it a prefab)? 0 Answers
Can isometric tiles be rotated? 0 Answers
How to make object use 2x2 tiles inn tilemap and tile palette? 0 Answers
How can i make the Unity2d grid use rounded numbers? 1 Answer