• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Apexuni · May 26, 2010 at 06:01 AM · resolutionguitexture

GUI texture resolution problem

hi

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.

Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Wolfram · Aug 04, 2010 at 04:20 PM

You can apply a scaling to all GUI elements, depending on the screen resolution. So somewhere in OnGUI(), call:

GUIUtility.ScaleAroundPivot(new Vector2(1,1)*Screen.height/768f,Vector2.zero);

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:

GUIUtility.ScaleAroundPivot(new Vector2(Screen.width/1024f,Screen.height/768f),Vector2.zero);

See also here, for alternative methods: http://answers.unity3d.com/questions/3594/rendering-gui-buttons-in-the-middle-of-the-screen/

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by jonas-echterhoff · May 26, 2010 at 12:23 PM

I'm not sure I fully understand what you want to do, but you can try using screen relative coordinates. So, instead of

GUI.Label(Rect(10,10,200,200), myTexture);

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).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by reptilebeats · Jan 02, 2012 at 07:40 PM

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;

 function Update(){
 
 transform.localScale = (Vector3(xScale,yScale,zScale));
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Meltdown · Feb 15, 2012 at 12:46 PM

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()

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Scale GUITexture to screen resolutions 1 Answer

Bulletproof way to do resolution independant GUI scaling? 2 Answers

Screen Resolution and GUI cutoff issue. Android. 1 Answer

GUITexture placement - Screen Resolution 1 Answer

How-to-make-GUI-Buttons-on-GUI-Texture-resolution-independent 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges