- Home /
Question by
unity_RWf9GR1xEiEvoQ · Oct 26, 2018 at 02:13 PM ·
tilemaptiles
How to get component from a tiled prefab which belongs to a tilemap
A I have a tilemap with prefabs tiles (transform + sprite render + custom script). How i can get the script from each tile ?
Vector3Int cellPosition = grid.WorldToCell(t.position); t.position = grid.CellToWorld(cellPosition); TileBase tile = tileMap.GetTile(cellPosition);
Comment
Answer by lgarczyn · Jan 26, 2020 at 09:16 PM
Old question, but tiles don't have components. You need to access tile.gameobject, check if there's a gameobject attached, and if so, use GetComponent on it. If you have custom TileBases, you need to upcast it into your class.