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

Get coordinates from colliding tile

Discussion in '2D Experimental Preview' started by M4x1, Apr 1, 2018.

  1. M4x1

    M4x1

    Joined:
    Mar 31, 2018
    Posts:
    1
    I´m very new to Unity and want to make a 2D platformer like Mario with Tilemaps. But I can´t figure out how to manipulate a specific tile in a tile map. Like when the Player hits a Block that only the one Block disappears or just collect one Coin. I have separate tilemaps for these Blocks. So I want something like this...
    Code (csharp):
    1.  
    2. void OnTriggerEnter2D(Collider2D col)
    3.     {
    4.         coin = col.gameObject;
    5.         points += 1;
    6.         coin.setActive(false);
    7.         }
    8.  
     
  2. furroy

    furroy

    Joined:
    Feb 24, 2017
    Posts:
    93
    If you aren't doing any scaling and keeping 1 tile is 1 unity unit, just floor your localpos to get the tile index.

    Code (CSharp):
    1. Vector3Int local = Vector3Int.FloorToInt(transform.InverseTransformPoint(worldCoord));
    2. Tilemap map = GetComponent<Tilemap>();
    3. TileBase tile = map.GetTile(local);