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 AndreasX12 · Apr 07, 2013 at 12:11 PM · guiresolutionscalescalingmonitor

Scaling GUI correctly according to game window resolution?

Hello, I know this question has been asked before, but after 2 hours of searching, I desided to write here :-)

My problem is that when I script the GUI on my main monitor (1920*1200) The gui looks normal (because that's the resolution i made the gui "fit" in) but when I try the game on a lower resolution monitor, the GUI is the same size as on the 1920*1200, and the gui is far to big. What is the easiest way to scale my gui so that it has a suitable size for different screen sizes?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by paulaceccon · Apr 07, 2013 at 12:39 PM

 using UnityEngine;
 using System.Collections;
 
 public class BackgroundController : MonoBehaviour
 {
 
     GUITexture _backgroundGUITexture;
 
     void Update()
     {
         Rect r = new Rect( 0, 0, Screen.width, Screen.height );
         if (_backgroundGUITexture)
             _backgroundGUITexture.pixelInset = r;
     }
     
     public void setBackgroundTexture (Texture bck)
     {
         _backgroundGUITexture.texture = bck;
         _backgroundGUITexture.enabled = true;
     }
 }
Comment
Add comment · Show 10 · 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 AndreasX12 · Apr 07, 2013 at 12:53 PM 0
Share

Hmm still doesn't scale to different screen sizes..

avatar image paulaceccon · Apr 07, 2013 at 01:05 PM 0
Share

I always use this script to rescale... You just have to attach it to the game object that contains you GUITexture.

avatar image AndreasX12 · Apr 07, 2013 at 01:14 PM 0
Share

Okay, it seems like that when i press play, the BackgroundGUITexture get's unasigned althrough i attached it in the Scene/editor. But if I (at runtime) attach the object with the guitexture, it work's although the size is 1007, 1030 and that is not even the size of the texture.. Strange..

EDIT: If I delete this line: _backgroundGUITexture = this.GetComponentInChildren(); it kinda work's althrough the size is still 1007, 1030.

avatar image paulaceccon · Apr 07, 2013 at 01:19 PM 0
Share

Sorry, I forgot about this... It was cause my texture was in a game object inside another game object, so I use GetComponentInChildren.

What is the size of the screen? It's weird, cause here Rect r = new Rect( 0, 0, Screen.width, Screen.height ); you should get a Rect in x,y = 0 and with the screen size. Here it works perfectly.

avatar image paulaceccon · Apr 07, 2013 at 01:40 PM 1
Share

What do you mean about the size of the GUI? The size of the texture in the screen? If so, you can create a method to change the Rect, passing the size... Something like:

 float myWidth = Screen.width;
 float myHeight = Screen.height;

 void Update()
 {
    Rect r = new Rect( 0, 0, myWidth, myHeight );
    if (_backgroundGUITexture)
      _backgroundGUITexture.pixelInset = r;
 }
 
 public void setSize (float width, float height)
 {
    myWidth = width;
    myHeight = height;
 }
Show more comments

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI adapting to screen resolution? 3 Answers

How to scale a GUI (Lagacy) grid? 1 Answer

GUI and Screen Resolution 1 Answer

Dealing with GUI size on iPhone 1 Answer

Editor and Device resolution mixed-up problem 0 Answers


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