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 tile from tilemap from Click.

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

  1. YagirX

    YagirX

    Joined:
    Jan 16, 2016
    Posts:
    15
    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:
    113
    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);
     
    YagirX likes this.