- Home /
Other
How can I attach a script to all of the tiles inside of my grid?
When I right click in the hierarchy and go to 2d -> Tilemap, it creates a grid. After I paint a bunch of tiles onto that grid with my palette, I see the tiles in the scene/game view, but I don't see those tiles as gameobjects in the hierarchy. How then can I attach a behavior script to those tiles?
Answer by SunnyChow · Oct 26, 2018 at 02:48 AM
A good tile map tool will never create tiles as individual gameobjects. It's horrible for performance. If you want to make a trigger, you should create a gameobject just for the grid you want. If you want things happen based on character's position, you should have just one gameobject to monitor character position and react based on this data
So how can I tell the player that he can walk on grass tiles but not water tiles?
https://docs.unity3d.com/$$anonymous$$anual/Tilemap-ScriptableTiles-Tile.html
i think you need to get the character's position, and use it to get the tile data
Answer by GameDBharat · Oct 26, 2018 at 03:49 AM
You can create a different palette for different objects. and attach scripts to those palette then assign the layer name for each palette or add Collider2D component for each palette check the Is Trigger. access them with tag name. i think this will help @sean244 .
I don't think you can attach either a script or a collider to a palette. Do you mean the Tilemap?
Follow this Question
Related Questions
Correct use of setTile to add tile to Tilemap 0 Answers
How can I access to a tile properties in a Tilemap? 0 Answers
Tilemaps making feature 1 Answer
Gaps between tiles in a tileset 1 Answer
GetTile always returning null 0 Answers