Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Best approach to define interactive screen areas regardless of it's resolution? 3 Answers

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

Always have GUI Texture at Said Place Regardless of Resolution 1 Answer

ASPECT RATIO FILTER IN OnGUI? 3 Answers

Multi-resolution!!! Sprite and GUI 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges