Search Unity

Help finding resources to learn Tiles/Tilemaps/TileBase/etc

Discussion in 'Getting Started' started by jacobw56, Dec 17, 2018.

  1. jacobw56

    jacobw56

    Joined:
    Dec 10, 2018
    Posts:
    1
    I'm trying my first "simple rogue-like" game with grid movement. I managed to get grid movement working pretty nicely and now I am trying to add the ability for the player to drop items on the ground, then possibly interact with them later. I've been through a number of tutorials, but none of them actually seems to come close to this functionality (surprising to me), and so I'm here asking for assistance if you've seen any learning resources that could help.

    The big issues with my approaches so far:

    I have several Tilemaps for the floor/walls/objects sitting on the floor/etc. My original idea was to insert a new tile under the player into my Tilemap of choice (I thought via SetTile), then later I could have the character go back over the tile and interact with it (I thought via GetTile). It turns out that I have been unable to find anything that works this way (and I suspect that Get/SetTile aren't actually meant to work this way at all, though I also don't know what they are for).

    I can, however, place a sprite under my player using, for example
    Code (CSharp):
    1. Instantiate(APrefab, transform.position, Quaternion.identity).GetComponent<GameObject>();
    however this gameobject doesn't live in any of my Tilemaps so I can't (I don't think) interact with it easily ever again once I lay it down. I also don't get any of the Tilemap properties like Sorting Order, which would be handy if I could just lay a Tile into a Tilemap at a given set of coordinates.

    Anyway, any help at all is always appreciated. My guess is that I am just googling the wrong things all together since I clearly don't understand how these objects work together.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Don't change the tile. The tile will continue to be whatever piece of floor it was before.

    Dropped (or otherwise dynamic) objects should be sprites, as you guessed. You'll need to make your own data structure for keeping track of these. Make a sort of WorldManager module (or whatever you want to call it) with methods to return the object (or list of objects, if there can be more than one) at any map position; to place an object on the map at a given position; and to remove an object from the map. Also, every object should know its map position.

    Once you have those, you'll be all set!
     
    jacobw56 and Schneider21 like this.