Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Trouble placing objects on 2D tilemap

Discussion in '2D' started by JustinCase88, Oct 3, 2022.

  1. JustinCase88

    JustinCase88

    Joined:
    Oct 3, 2022
    Posts:
    2
    I am making a hex tilemap, and want to place some objects on top of it from code. One is a sprite, and one is a simple text. Both of them go in a canvas on top of the tilemap.

    When i add the sprite (using Instantiate and myHexMap.CellToWorld(new Vector3Int(x, y, 10))), the objects are placed where I expect, and when I move the camera they follow the map.

    However, when I add the text in the same way, it is not placed correctly (different coordinates land on basically the same position), and they do NOT move with the camera, and stay on the same spot on the screen.

    Seems the difference is that the sprite only has a Transform, and the Text has a RectTransform (as i have tested with other objects).

    There must be something basic I am missing here. Can someone point me in the right direction?
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
  3. JustinCase88

    JustinCase88

    Joined:
    Oct 3, 2022
    Posts:
    2
    Yeah, that was the main issue, thanks. Still have some things to learn about placement and sort orders though, as I can never quite get it the way I want. :)