Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

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

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

  1. kevinyao93


    May 16, 2020
    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.