GUI Text Alignment

Hi guys,

I have two questions to ask, firstly, How can I align a gui text to the exact position I want. My game will be run in the fixed aspect ratio and I am doing the alignment by adjusting the pixel offset.

It looks good in the game preview mode, but when when it runs in the actual game, it lose the exact position. I really have no idea with this.
Here’s my code.

guiText.text= 100;
guiText.pixelOffset = Vector2 (Screen.width/4+200, Screen.height/4+170);

Or can I define my GUItext in the GUI.BeginGroup?

And another question is how do I put my text over a GUItexture.
I have a background picture that should be under the GUItext, but the text is under the picture in the game.How to solve this?

Thanks in advance!!

GUIText/Texture is the old GUI system of Unity. To change the one on top you have to change the z position.

The new GUI system is done inside OnGUI functions. You would need a rect (the x and y are your current pixelOffest I suppose) and probably a style. If you want some rect functions and alignements stuff, check this out.

I had the same issues you were having, at least I think so!

To move the texture behind the text:
In the game view, not the scene view, click on the GUITexture and change the transform value to move the texture behind the text.

To move the text:
I believe since you’re using GUIText, and that’s not drawn at run-time like OnGUI, you can move it the same way as you can the GUITexture. Go to the game view, click the text, and change the transform properties around until you get it where you want.

I had the same issues you did in that what I was seeing in the editor was not the position that the GUI was appearing in the build. First make sure you’re resolution in the editor is the same as what your build will be. Then, make sure that any windows in the bottom of the editor are out of the way. I had dragged the Hierarchy and Project views down to be as small as possible but when I moved them off to the side, the screen got bigger and my GUI moved. Then, make sure Maximize on Play is checked. That way when you run the game in the editor, you make sure that your resolution is exactly what it will be in your build.

Maybe these are common sense things and they’re not the problems you’re having but it stumped me for a long time.

And as far as GUIText and GUITexture being old and obsolete, I’m not so sure. I like them better because you can move them and see what’s going on as I’ve described. I also believe they’re less expensive than dynamically creating the stuff using OnGUI. The only thing I ended up using OnGUI for was for sliders since I didn’t see an easy way to create them with GUITextures.

I hope some of this helps!