Author Topic: Move label in absolute pixels  (Read 1710 times)


  • Guest
Move label in absolute pixels
« on: January 26, 2013, 07:20:05 PM »
I posted this on Unity Answers but since it's concerning NGUI I figured I might get a more accurate response here:

I'm creating an item tooltip for my game using NGUI - consisting of a sprite background and multiple UILabels.
I'm moving these UILabels down/up depending on the number of rows of the previous ones - for instance, if an item has a longer description, the label showing its stats will be moved lower down to not overlap. I'm using this simple code to move the labels - labelText4 is a UILabel:

  1. labelText4.transform.position = new Vector3
  2. (
  3. labelText4.transform.position.x, labelText4.transform.position.y-0.055f,
  4. labelText4.transform.position.z
  5. );

This code for instance moves the fourth label down a bit.
However, this does not move the label in absolute pixel values - in other words, if I change the screen resolution it will not be moved correctly. How can I move an UILabel through script like I move any NGUI element in the Unity Editor?


  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Move label in absolute pixels
« Reply #1 on: January 26, 2013, 07:49:26 PM »
Use transform.localPosition, not transform.position.


  • Guest
Re: Move label in absolute pixels
« Reply #2 on: January 26, 2013, 08:55:56 PM »
Thank you, how stupid of me not to realize this :P

Works fine now!