Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

How to find the specific tile/tilebase on a cell?

Discussion in '2D' started by aybarsmete1, Nov 9, 2019 at 8:31 AM.

  1. aybarsmete1

    aybarsmete1

    Joined:
    Oct 26, 2019
    Posts:
    32
    I don't know if this even exists or not, but I'm trying something like this (tp is a tilemap):
    Code (CSharp):
    1. Vector3Int currentCell = tp.WorldToCell(transform.position);
    2. if(currentcell.tile = dirt)
    3. {
    4. Lorem.ipsum;
    5. }
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    1,351
    Hi @aybarsmete1

    "I don't know if this even exists or not, but I'm trying something like this (tp is a tilemap):"

    You first have to get the coordinate in tilemap "space" like you are doing.

    Then you will have to get the tile, worldToCell only gives you a coordinate, Vector3Int doesn't have any property like .tile.

    To get tile, you have to use GetTile of tilemap - see the docs:
    https://docs.unity3d.com/ScriptReference/Tilemaps.Tilemap.GetTile.html

    It gives you Tilebase describing a tile at that coordinate (if tile exists).

    Edit: IIRC you at least can get the name of the tile from Tilebase, so you can use that to identify your tile type.

    BTW ...you are doing assignment in your if statement, where you should be doing comparison.
     
    Last edited: Nov 9, 2019 at 4:21 PM
  3. aybarsmete1

    aybarsmete1

    Joined:
    Oct 26, 2019
    Posts:
    32
    Thanks -btw I figured the procedural generation out, it now generates randomly-