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. Dismiss Notice

Can I get the already drawn tiles in the form of an array as a tilemap?

Discussion in '2D' started by wlgh7546, Aug 1, 2022.

  1. wlgh7546

    wlgh7546

    Joined:
    Feb 8, 2022
    Posts:
    2
    There are a tile, b tile, and c tile, so you have to manage each separately.


    I found the x and y coordinates of each tile through an internet search.
    Code (CSharp):
    1.     void Start()
    2.     {
    3.          tileWorldLocations = new List<Vector3>();
    4.  
    5.          foreach (var pos in tilemap.cellBounds.allPositionsWithin)
    6.          {
    7.              Vector3Int localPlace = new Vector3Int(pos.x, pos.y, pos.z);
    8.              Vector3 place = tilemap.CellToWorld(localPlace);
    9.  
    10.  
    11.  
    12.              if (tilemap.HasTile(localPlace))
    13.              {
    14.                  tileWorldLocations.Add(place);
    15.                 tile = tilemap.GetTile(localPlace);
    16.  
    17.  
    18.              }
    19.          }
    20.  
    21.  
    22.     }

    But what I want is to separate each tile into a, b, c tile and use it like a game object.
    To use it as a game object, I need to use the TileData format, but I don't know how to use that method. Thank you in advance for your answer.
     
  2. vonchor

    vonchor

    Joined:
    Jun 30, 2009
    Posts:
    238
    If what you are trying to do is to actually turn a tile instance retrieved from a Tilemap into an actual GameObject: the tile instance is (basically) a Scriptable Object. You can't turn those into GameObjects.

    TileData is mostly an internal data structure used within Tile classes and has nothing to do with GameObjects.

    What you can do is get the Sprite reference from the Tile retrieved from GetTile. You can programmatically create a GameObject with a Sprite Renderer and use the Tile's sprite in the renderer.

    It's hard to comment without knowing what you're trying to do...
     
    Last edited: Aug 1, 2022
  3. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    if you want to use gameobject as tile you cant use tilemap feature

    tho i dont recommend that you do that
     
  4. wlgh7546

    wlgh7546

    Joined:
    Feb 8, 2022
    Posts:
    2
    I'm sorry my explanation was short.

    The blocks the character can step on are different for each state of the character.

    For example, when the character is in a state, a tile is activated, b, c, and tiles are deactivated, and when a character is in b state, a and c tiles are deactivated. There was also a mistake in placing blocks on the tile when it was in a state.

    So, after arranging all tiles on one map, I would like to collect a, b, and c tiles in an array by name, and then enable/disable depending on the state. If there is another good way, please let me know.
    upload_2022-8-2_1-4-21.png
     

    Attached Files: