Hello Guest

Author Topic: Align tk2d Sprite with Unity UI  (Read 5537 times)

pdform

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
    • The Balance Inc
Align tk2d Sprite with Unity UI
« on: August 17, 2015, 04:15:18 pm »
Hi,

I've decided to port my HUD to Unity UI mainly for the great layout and text handling facilities, however, I need to align my HUD to the game map and place some sprites exactly over UI icons. How can I obtain a valid tk2d sprite position given Unity UI rect transforms, for instance, their center and edges, so I can smoothly align and position sprites along UI elements? I've tried fooling around with camera's NativeResolution, TargetResolution, ZoomFactor and rect.sizeDelta, but none of the transformations I tried worked.

Thanks in advance!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Align tk2d Sprite with Unity UI
« Reply #1 on: August 21, 2015, 08:58:38 am »
Hi there,

There isn't a magic way to match these up. They're 2 completely different systems.
Having said that though, it IS possible.

If you attach the sprite / cube / whatever 3D element as a child of the GUI element, it'll appear where the GUI elements Pivot is in the scene view.
You'll also need to set your canvas to Screen Space Camera for the object to appear in game view.

Getting size is a bit more involved - you're better off writing a script for that.