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

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

Discussion in '2D' started by aybarsmete1, Nov 9, 2019.

  1. aybarsmete1

    aybarsmete1

    Joined:
    Oct 26, 2019
    Posts:
    43
    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:
    2,637
    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
  3. aybarsmete1

    aybarsmete1

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