Author Topic: Label problem, set text by code offsets the text  (Read 5038 times)

Tiles

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Label problem, set text by code offsets the text
« on: August 01, 2013, 06:45:18 AM »
I am a bit baffled at the moment. Something i did a few dozen times before makes trouble now. I set the text of the label to another string by code at runtime. And the position of the string changes by that.

It`s a small string that i set to "Press Enter" while a conversation, and at the last paragraph to "Move on"

I have reduced the trouble maker to the text positions. When i use the upper left corner as the center of the text, then everything is fine. When i use the center of the string, then i get an offset when i change the text. I need the center because i scale this string in and out to animate it.

I have solved it by offsetting the text in the first place, and change the string to whatever i need. So that the string is offset in every case. But that`s not really a nice solution.

Is this a known issue? Do you know a better workaround or a fix here?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Label problem, set text by code offsets the text
« Reply #1 on: August 01, 2013, 05:48:03 PM »
A screenshot of your scene view with the label selected would help. Simply changing the text certainly doesn't move the label.

Tiles

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Re: Label problem, set text by code offsets the text
« Reply #2 on: August 02, 2013, 03:26:43 AM »
Indeed. Changing the text shouldn`t change the position. That`t why i am so baffled :)

I have made a short video where you can see the problem a bit more clear. The label is selected while that.

1.5 MB: http://www.reinerstilesets.de/ext/unity/textchangingposition_x264.mp4

Just that i have mentioned it. The tween script doesn`t have any influence here. The problem is still there when i remove it.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Label problem, set text by code offsets the text
« Reply #3 on: August 02, 2013, 11:11:45 AM »
Your default "my text" likely has an enter (\n) at the end. Since it's center aligned, it would move it up by a half line.

Tiles

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Re: Label problem, set text by code offsets the text
« Reply #4 on: August 04, 2013, 02:58:51 AM »
Ha, so simple. Indeed, that was it. You`re a genious. Many thanks :)

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Label problem, set text by code offsets the text
« Reply #5 on: August 04, 2013, 10:01:08 AM »
:)