Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

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:
    109
    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);
     
unityunity