Search Unity

Identifying your tilemap tile sprites

Discussion in '2D' started by Deleted User, Feb 13, 2018.

  1. Deleted User

    Deleted User

    Guest

    Good day. I've been stuck with my first project for two days because of this, so at this point I'm desperate.

    In my project a player moves square to square in a 2D grid. For easy map creation I am learning use tilemap functionality recently added to unity. I make a tilemap in my hierarchy using Create>2D Object>Tilemap. Then, using different sprites (according to what I want a certain tile to represent), I draw my maps using the palette (i.e. place "Sand", "Water1").

    Before I execute the player's move function to a square, I need to find out what square it is. If it's "Hot_lava" (unpassable), or maybe "Steep_Hill" (deducts more move points). Since i'm just adding sprites to a palette, their name is the only indicator of what it is, I need to somehow reach that.

    For the most part I've been trying tilemap.GetTile(position), because that seems like the best and easiest way to access the cell I know the position of. But how do I extract the sprite name? Is there really no way? If so, what are some easy alternatives I can use? One that comes to mind is changing the color property of every paletteTile file and in my script read the color with GetColor, but that changes the look of the sprite itself, so it is not that optimal to use as a tag. Any help/ideas appreciated!
     
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    An easy way to solve it is to use multiple tilemaps, and have one with "dangerous" tiles and one with "ordinary" tiles and so on.
     
    alexisnotonffire likes this.