Search Unity

Tile Map Different ground types

Discussion in '2D Experimental Preview' started by KhenaB, Jul 31, 2018.

  1. KhenaB

    KhenaB

    Joined:
    Aug 21, 2014
    Posts:
    267
    Is it possible to "tag" tiles in the same tilemap to be recognized as types of ground for my footstep sounds, I know i could have a tilemap for each different surface types but I'd like to keep it simple in a single tileset, it would be nice to be able to tag each tiles in the Tile Palette and be able to access that tag, is there another way to do this?
     
  2. KhenaB

    KhenaB

    Joined:
    Aug 21, 2014
    Posts:
    267
    I created a custom tile with some public variables but I don't understand how to access them, GetTile returns WoodTile but I'm unable to access it's variables, some help would be appreciated.

    ScriptableTile.png

    Code (CSharp):
    1. Tilemap tileMap = collider.GetComponent<Tilemap>();
    2. TileBase currentTile = tileMap.GetTile(tileMap.WorldToCell(collisionPos));
    3. print(currentTile);
    WoodTile.png
     
  3. KhenaB

    KhenaB

    Joined:
    Aug 21, 2014
    Posts:
    267
    Had to do it like this instead:

    Code (CSharp):
    1. Tilemap tileMap = collider.GetComponent<Tilemap>();
    2. GroundTile currentTile = tileMap.GetTile(tileMap.WorldToCell(collisionPos)) as GroundTile;
    3.  
    4. if (currentTile is GroundTile)
    5. {
    6.     print(currentTile.groundType);
    7. }