Cell size to Canvas size
Hi,
I want a panel (inside my Canvas) to be at a given tile position.
Let's say i have my tile at position (1, 2, 0) on my tilemap, I transform this pos to world:
var cellWorldPos = Tilemap.CellToWorld(tilePos); // -> (1.0, 2.0, -1.0)
Then I transform it to Viewport pos:
var cellViewportPos = cam.WorldToViewportPoint(cellWorldPos); // -> (0.6, 0.7, 999.0)
And I set my panel pos:
ConfirmBox.transform.position = new Vector3(cellViewportPos.x, cellViewportPos.y, ConfirmBox.transform.position.z);
First problem: my panel is now at pos (-591.4493, -332.3198, 0) (not tile pos).
Second problem: if , instead I set the pos the panel's local pos (so (0.6, 0.7, 0)), it isn't at the tile pos either.
First case when setting to panel's world pos (the green square is the tile, the green check symbol is a part of the panel).
Second case when setting to panel's local pos.
Answer by Akrone · Oct 31, 2018 at 01:17 PM
I found the answer, indeed i must use ConfirmBox.transform.position = cam.WorldToScreenPoint(tilePos)
! I thought I already tried that but it seems that I'm wrong. :/
Anyway, resolved.
Your answer
Follow this Question
Related Questions
How to Hide/Show 3d text according to player's position? 0 Answers
Trouble getting my Pause menu "above" my Scene canvas. 1 Answer
Convert GPS coordinates to unity 0 Answers
UI Elements repositioning and resizing when playing game 1 Answer
Converting mouse(touch) position with ScreenToWorldPoint doesn't work. 1 Answer