Search Unity

Question 3D Hex-Tilemap GameObjects get tile in code.

Discussion in 'World Building' started by kevinyao93, Sep 25, 2022.

  1. kevinyao93

    kevinyao93

    Joined:
    May 16, 2020
    Posts:
    2
    I recently just started getting into unity, and what I'm attempting to do is create a simple T-RPG with a hex based grid. I was going to have each of the tiles represent a separate grid, and to create the map, I had used the 2d tilemap, and used the GameObject Brush to orient each tile.

    I've been trying to use multiple tilemaps to represent objects on the ground, and character models accordingly. I
    I was wondering how I would go ahead and be able to -

    1. Get each individual tile in the grid. (Maybe get an array of the created tiles?)
    2. Be able to mutate each tile (i.e. replace one tile with another, replacing game objects) depending on actions that are taken within the game.


    While I guess I could generate all of the tiles through code, I was hoping for a method to get and replace individual tiles. Another method I guess that could maybe work, would be creating a base map of the coords and populate the tiles for each of these, and iterating through all of the tiles, but it seems like it would end up being really inefficient and I was wondering if there was any better way to do that.

    Please let me know if I need to clear anything up.