Search Unity

Tile Map Get tile from tilemap from Click.

Discussion in '2D Experimental Preview' started by YarikX, Nov 2, 2018.

  1. YarikX

    YarikX

    Joined:
    Jan 16, 2016
    Posts:
    4
    Help. I want to get tilemap tile. But I have more than one tilemap. Help. I want to receive coordinates when clicked so that later I can get a tile using the GetTile function.

    upload_2018-11-2_16-34-0.png
     

    Attached Files:

  2. qqqbbb

    qqqbbb

    Joined:
    Jan 13, 2016
    Posts:
    103
    Code (CSharp):
    1. Vector3 mousePos = MainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f));
    2. int tilePosX = Mathf.FloorToInt(mousePos.x);
    3. int tilePosY = Mathf.FloorToInt(mousePos.y);