- Home /
How to attach a gameobject onto a tile in a tilemap during runtime?
I'm building a tower defense game where the player will walk around and place/build towers. I've already set up the very basics of a pointed top hexagon tilemap with the thought that the towers would occupy one hexagonal grid space. The towers are separate game objects that will just sit on top of the grid.
Basically, I want the player to pick up a tower from a shop, walk over to the desired tile, and then when the player places the tower, it should attach the gameobject to that tile locking it's position and preventing a new tower from being placed on the same tile. I've done some searching and haven't been able to find any example of my problem being implemented which has caused me to be a little bit lost about how to proceed.
My first idea was to add a gameobject slot(aka variable/reference) to each tile (probably using scriptable objects??) My second idea would be to make a grid manager script that would act as a middle man, effectively keeping track of all the towers on the field, assigning new towers' positions correctly when they get made, and prevent the player from placing multiple towers on the same tile. I'm leaning towards option 2, but I'm not sure which is the best option or if there is an easier solution out there that I have missed.
Your answer
![](https://koobas.hobune.stream/wayback/20220613044646im_/https://answers.unity.com/themes/thub/images/avi.jpg)
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
Tilemaps making feature 1 Answer
Can you add sprites to existing sprite sheet without breaking the tile pallet and in-game tiles 0 Answers
Spawning a specific Tile in a random position a certain distance from the player character 1 Answer