i make HUD for my game i am using GUI texture & i change the height& width also X&Y position all these setting suitable for 1024 x 768 resolution but the problem is when i change resolution like any other resolution or Web player resolution. then my original settings gone.
how can i adjust automatically my HUD even i change my resolution.
You can apply a scaling to all GUI elements, depending on the screen resolution.
So somewhere in OnGUI(), call:
Note that this assumes you placed your elements for the 1024x768 resolution. Also, it will keep the aspect ratio, which means if you choose a 16:9 resolution, the left and right borders of the screen will not contain GUI-Elements. If yuo want to stretch your GUI elements to compteletly fill other aspect ratios, such as 16:9, use:
See also here, for alternative methods: http://answers.unity3d.com/questions/3594/rendering-gui-buttons-in-the-middle-of-the-screen/
I'm not sure I fully understand what you want to do, but you can try using screen relative coordinates. So, instead of
you'd have something like
GUI.Label(Rect(Screen.width * 0.05,Screen.height * 0.05, Screen.width * 0.2, Screen.height * 0.2), myTexture);
, so it resizes automatically with the screen size. You could adapt this, or use GUILayout for some of it, depending on how you want your GUI to scale with the screen size (often you might just want to fix the position, but not change the size of your GUI, so your textures remain pixel-precise).
this is what i use it will stretch the image in free aspect, but everything else is fine
var xScale : float = 1;
var yScale : float = 1;
var zScale : float = 0;
transform.localScale = (Vector3(xScale,yScale,zScale));
I found the best way to do GUI texture sort of stuff is to create a simple 2 triangle plane and attach it to the camera.Once you’ve got it aligned how you want in the view, no matter the resolution or screen size it always looks good.
If you need to scale a power bar for instance, by default it scale smaller/larger from middle, thus affecting both ends.
To resolve this use the CreatePlane.cs script from the Unify wiki and set the anchor value to whatever anchor your scaling requires.
Not to mention you get away from using the ghastly OnGUI()