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

Return whether or not a tile has something on it

Discussion in '2D Experimental Preview' started by CrowbarSka, Feb 13, 2018.

  1. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    192
    I'm trying to do a check to find out where enemies can spawn in my level. If there is a tile placed on a grid space, they should not spawn there, but if there is nothing then that position should be added to a list of possible spawn points.

    I'm struggling to figure out how to return data about any given tile so I know it's safe to spawn there.

    I've tried:

    if (tileMap.HasTile(position))
    {...}

    if (tileMap.GetColliderType(position) == Tile.ColliderType.None)
    {...}

    But both of these always return true for every tile, as if the entire tilemap is empty.

    I'm now looking into the GridInformation addon script (https://github.com/Unity-Technologi...ap/GridInformation/Scripts/GridInformation.cs) but I can't get my head around it.

    Any help would be appreciated.
     
  2. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    192
    Arrghh, never mind... I was basing this off some code I found that was using a top-down setup instead of side view, so Y and Z were inverted. Ignore!
     
  3. eeshaansk

    eeshaansk

    Joined:
    Aug 1, 2020
    Posts:
    3
    i hadnt tried tilemap.hastile
    tysm i finally got to know how to work it out
     
    CrowbarSka likes this.