Positioning a GUITexture

Hi,

I’m having problems getting this to work (outside Unity Editor).

What i do, is i add a GUITexture, and i place everything at zero, Position, Rotation, Scale and Pixel Inset (x,y), only the width and height have a value, in this case (100,100).
Then, in code i position the GUITexture like this :

guiTexture.pixelInset.x = (Screen.width / 2) - 182;
guiTexture.pixelInset.y = (Screen.height / 2) - 80;

This code works great, and i can change resolution inside Unity Editor, and the GUITexture position adapts perfectly.
However, when i make a build, and run the game outside of Unity, my GUITexture doens’t position itself correctly in the Y axis, it gets either higher or lower, but not in the desired position.
Anyone spots an error here ?

thanks,
Bruno

1 Like

why are you not moving the GUITexture from the position var?

its easier IMHO.

Check the alignment of the texture and the center :smile:

Well, with the position i can’t find the exact place where to place it :?
If i use the position, i have values between (0,1), and the moment i change resolution, the position is diferent.
That’s why i was using pixel values, because with pixel i can know what screen resolution i’m on, and adapt the position depending on those values.
How would you use the position, if it changes when i change resolution ?
And, how do you check the alignment and the center of the texture ? :slight_smile:

Hello,

just use a simple rule of 3

positionConverted = (Value you want to find)/Screen.width or height

Well, i did as you sugested, but doens’t work either :sweat_smile:

I measured position.x, and position.y, with a resolution of 1280x800.
In that resolution, the position coordinates are (0.362,0.34).
When i change resolution, as expected everything gets out of it’s place.
So, i did this :

pX = (Screen.width * 0.362) / 1280;
pY = (Screen.height * 0.34) / 800;

transform.position.x = pX;
transform.position.y = pY;

Still a no go, everything out of place.
Is there something wrong in that code ?

thanks,
Bruno

Dont worry :stuck_out_tongue: I explained myself wrong.

Lets say I want to put your texture just in the middle of the screen ok?

So what I would do Is:

pX = (Screen.width/2) / Screen.width;
pY = (Screen.height/2) / Screen.height;

transform.position.x = pX;
transform.position.y = pY;

Where do you want to put your texture? what you have to do is to play with the values that are being divided (in this case Screen.width/2 and Screen.height/2).

I hope this helps you out :smile:

Thanks,
This is really bizarre, your technique does work, but only in the Y axis, the X axis gets all messed up.
So, i made a mix of the techique i pasted initially, and a mix of yours, the original one for the X,and yours for the Y, and now works, but still, doens’t look clean, lol

rofl,

that should work on both X and Y axis, it doesnt matter! its just playing with numbers! hahaha

GUI textures have viewport coordinates, ‘x’ and ‘y’ positions can’t be less than 0 and more than 1.