Search Unity

Changing anchored Position

Discussion in 'UGUI & TextMesh Pro' started by Shadowing, Aug 26, 2018.

  1. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    I have a chat box where I want to expand its size.
    In the past if i wanted to expand it in height by say 300 units
    All i had to do is change the sizeDelta to current position + 300 / 2 or height / 2 and that would keep the chat in place.

    For some reason today it doesn't do this. 300/2 moves the chat box up way to far.

    Anyone have any ideas.
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    it is probably because of your anchors... (however, your math doesn't really make sense)
    how are the anchor values?
    I always prefer to have the anchors on the borders so that the size delta and anchored position are at zero. That way you could simply change the anchor values to resize it (however, they are relative coordinates)...
     
  3. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    You've got to pay attention to your anchors and your pivot when repositioning objects from script.
     
  4. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    pivot is only important under certain circumstances. 90% of the times it doesn't really matter. However, you are right that the pivot also might be important. But usually you don't want to change it via code again.