- Home /
localPosition.y returns wrong value
Hello,
a UI image element that has been anchored to the top of the parent and with stretched width and also with "-150 Pos Y" will not return "-150" when calling theObj.localPosition.y
. Instead it will return a position based on the viewports height. What is up with the value? Why will it not return "-150"?!
Answer by DiegoSLTS · Mar 09, 2015 at 03:11 PM
Don't use localPosition for UI elements, it has different values than the ones you see in the Rect Transform depending on anchors and pivots, that's why the inspector doesn't show you the local position directly.
If you want to get the value of "Pos Y" you see in the inspector use theObj.anchoredPosition.y
Omg, thank you so much. They really ought to tell people this stuff! Why can't I find that answer anywhere but here??
Ugh, Unity really sucks sometimes....
Your answer
Follow this Question
Related Questions
How to find width and height of game object, Unity2D 2 Answers
Unity not dividing correctly C# camera pixel width & height 1 Answer
Having an issue with setting the minimum size for a field size 0 Answers
How to change the Width and Height in the script C#? (New Gui Unity 4.6 beta) 2 Answers
Multiple Cars not working 1 Answer