- Home /
Text in wrong position after I build a project
I'm using the new UI system.
Everything looks perfect in the editor, but as soon as I build to iPhone, some of my elements are in the wrong position. The elements that are in the wrong spot are the ones that I control with a coroutine. I'll tell the script to add 50 units to the position.x of a text element when I press the pause button. Looks great when I'm in the editor, but in the iPhone the text doesn't move far enough. If I move it to the left, it doesn't move far enough. If I move it to the right it doesn't move far enough. Not sure what I'm doing wrong.
Answer by daveinpublic · Jul 28, 2015 at 01:43 PM
I figured it out, I need to use localPosition instead of position when I alter the text. I'm using a Canvas Scaler on the the Canvas.
Answer by OctoMan · Jul 16, 2015 at 07:43 AM
I suggest using the new Unity 5 Canvas System, and use Canvas scaler and choose setting > UI Scale Mode > Scale with Screen size.
If you still want to use the old OnGUI() then you need to work in % of the screen, which means, you need to devide your screen size by the needed amount, and fit it until its at the right spot. Example: Screen.width / 0.5 = 50% so this will be always centered on the x axis.
Answer by Yuri0011 · Jul 16, 2015 at 06:36 AM
If you are displaying the GUI through a script I had the same problem. Instead of setting the specific location for the GUI you need to set it so far from the center of the screen. This will help,
GUI.Box (Rect ((Screen.width / 2) - 100, (Screen.height / 2) + 200, 50, 50), "Text");
It says the Box is 100 units left of the center and 200 units below the center of the screen. then it says the box will be 50 by 50 units and the Text that will be displayed in the box will be Text.
Answer by everything_appz · Jul 16, 2015 at 06:59 AM
The problem is with the pivots. Go to the transform of the Text Gameobject in the inspector and you should see a box. Click the box and it should expand. Hold Shift and Alt at the same time than choose from all the boxes the position closest to where you want your button or text. Than when there are different resolutions it will always be where it should.
Hope this helps.
Answer by unity_dyG3Ag-Fm1v-jg · Aug 11, 2018 at 07:54 AM
if you got problem in GAME view you can unpress "gizmos" tab up there.
Your answer

Follow this Question
Related Questions
Starting coroutine from button does not work as expected 2 Answers
Strange Interaction Between UI, Coroutines, and Content Fitters: Corrections Are Very Welcome 0 Answers
Mouse Idle UI question 0 Answers
Smoothly moving a rectTransform by script 1 Answer
Changing multiple UI.Image source image downloaded via WWW class 0 Answers