Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Different ground types

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

  1. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    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. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    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. Khena_B

    Khena_B

    Joined:
    Aug 21, 2014
    Posts:
    273
    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. }