Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Dreeka · Aug 15, 2011 at 10:39 AM · guiresolutionscale

Scaling the GUI with different screen resolutions

Hello,

I am creating the main menu of my game. How should I do the scaling, so it would fit to any screen resolution between 800x600 and 1366x768?

I have tried using Screen.width and Screen.height to scale and position every element from the background to the buttons, however, there are a great difference between the lowest and the highest resolution (they fit in the scene, bot doesn't look good at some resolution).

Any idea should I do the scaling?

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

6 Replies

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

Answer by aldonaletto · Aug 15, 2011 at 10:47 AM

You can change the GUI matrix to follow the screen resolution - this changes everything in the GUI world: fonts, textures, screen coordinates. Take a look at this question, which I answered some time ago and includes all the GUI matrix stuff.

Comment
Add comment · Show 6 · 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 Dreeka · Aug 15, 2011 at 10:51 AM 0
Share

Thank you for your help :)

avatar image RIw · Jan 27, 2015 at 08:31 PM 0
Share

This link doesn't work

avatar image jellyberg · Feb 07, 2015 at 07:37 PM 0
Share

WOR$$anonymous$$ING LIN$$anonymous$$ ADDRESS: http://answers.unity3d.com/questions/150736/script-gui-units.htm

avatar image asperatology jellyberg · Oct 18, 2015 at 11:40 PM 0
Share

Both URLs don't work anymore.

avatar image grimmdeveloper asperatology · Oct 25, 2015 at 05:18 AM 0
Share

You just need to add l at the end. http://answers.unity3d.com/questions/150736/script-gui-units.html

Show more comments
avatar image
2

Answer by vfxjex · Sep 25, 2013 at 09:05 AM

maybe this will help

 #pragma strict
 var skinGui:GUISkin;
 
 //the GUI scale ratio
 private var guiRatioX:float;
 private var guiRatioY:float;
 //the screen width
 private var sWidth:float;
 private var sHeight:float;
 //A vector3 that will be created using the scale ratio
 private var GUIsF:Vector3;
 var sizegui:int;
 
 
 function Awake()
 {
     //get the screen's width
     sWidth = Screen.width;
     sHeight = Screen.height;
     //calculate the rescale ratio
     guiRatioX = sWidth/1920 * sizegui;
     guiRatioY = sHeight/1080* sizegui;
     //create a rescale Vector3 with the above ratio
     GUIsF = new Vector3(guiRatioX,guiRatioY,1);
 }
 
 
 function OnGUI() {
 GUI.skin = skinGui;
 
 GUI.matrix = Matrix4x4.TRS(new Vector3(GUIsF.x,GUIsF.y,0),Quaternion.identity,GUIsF);
 
 
 
 if(GUI.Button(Rect(1,4,50,51),"hello")){
     
     }
 }
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 ArnB · Jun 09, 2014 at 02:46 AM

I know this is old but for future visitors I wrote a script to scale GUITextures and GUIText objects just attach to the object ;)

http://www.as-int.com/dev/GUI-scale-script-for-Unity/

Comment
Add comment · Show 1 · 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 Unity Ninja · Aug 01, 2014 at 12:51 PM 0
Share

hey its not opening anything!

avatar image
0

Answer by okimacera2 · Jan 02, 2015 at 11:05 AM

Hey :D There is my GUI AUTo SCALER .js You just need to set StartResolutions before start game :))

var CalculatePositionForNewScreen:boolean=false; var CalculateScaleForNewScreen:boolean=false; var StartResolutions:Vector2; var OffsetX:float; var OffsetY:float; var FindOffsetStart:boolean; private var Can:boolean;

function Start () { if(FindOffsetStart){ FindOffset(); }else{ Can=true; } } private var XFaz:float; private var YFaz:float;

function Update () { var Widht=GetComponent.().pixelInset.width ; var Height=GetComponent.().pixelInset.height;

if(Can){

if(OffsetX==0){ XFaz=((Widht-20)/2); }else{ XFaz=0; } if(OffsetY==0){ YFaz=((Height-20)/2); }else{ YFaz=0; } GetComponent.().pixelInset.x=((Screen.width)/2)-XFaz-OffsetX;

GetComponent.().pixelInset.y=((Screen.height)/2)-YFaz-OffsetY; CalculateOffset(); } }

function FindOffset () { var Widht=GetComponent.().pixelInset.width ; var Height=GetComponent.().pixelInset.height;

OffsetX= ((Screen.width)/2)-GetComponent.().pixelInset.x; OffsetY= ((Screen.height)/2)-GetComponent.().pixelInset.y;

yield WaitForSeconds(0.1); CalculateOffset();

}

function CalculateOffset() { var Widht=GetComponent.().pixelInset.width; var Height=GetComponent.().pixelInset.height; var Xk=(StartResolutions.x)/Screen.width; var Yk=(StartResolutions.y)/Screen.height; if(CalculatePositionForNewScreen){ OffsetX=OffsetX/Xk; OffsetY=OffsetY/Yk;

yield WaitForSeconds(0.001); StartResolutions.x=Screen.width; StartResolutions.y=Screen.height; } Can=true; if(CalculateScaleForNewScreen){ GetComponent.().pixelInset.width/=Xk; GetComponent.().pixelInset.height/=Yk; }

}

Comment
Add comment · Show 1 · 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 okimacera2 · Jan 02, 2015 at 11:06 AM

Meybe it will help :) In js :) you just shoult be set StartResolutions before start the game :))

 var CalculatePositionForNewScreen:boolean=false;
 var CalculateScaleForNewScreen:boolean=false;
 var StartResolutions:Vector2;
 var OffsetX:float;
 var OffsetY:float;
 var FindOffsetStart:boolean;
 private var Can:boolean;
 
 
 function Start () {
 if(FindOffsetStart){
 FindOffset();
 }else{
 Can=true;
 }
 }
 private var XFaz:float;
 private var YFaz:float;
 
 function Update () {
 var Widht=GetComponent.<GUITexture>().pixelInset.width ;
 var Height=GetComponent.<GUITexture>().pixelInset.height;
 
 if(Can){
 
 if(OffsetX==0){
 XFaz=((Widht-20)/2);
 }else{
 XFaz=0;
 }
 if(OffsetY==0){
 YFaz=((Height-20)/2);
 }else{
 YFaz=0;
 }
 GetComponent.<GUITexture>().pixelInset.x=((Screen.width)/2)-XFaz-OffsetX;
 
 GetComponent.<GUITexture>().pixelInset.y=((Screen.height)/2)-YFaz-OffsetY;
 CalculateOffset();
 }
 }
 
 
 
 function FindOffset () {
 var Widht=GetComponent.<GUITexture>().pixelInset.width ;
 var Height=GetComponent.<GUITexture>().pixelInset.height;
 
 OffsetX= ((Screen.width)/2)-GetComponent.<GUITexture>().pixelInset.x;
 OffsetY= ((Screen.height)/2)-GetComponent.<GUITexture>().pixelInset.y;
 
 yield WaitForSeconds(0.1);
 CalculateOffset();
 
 }
 
 
 function CalculateOffset() {
 var Widht=GetComponent.<GUITexture>().pixelInset.width;
 var Height=GetComponent.<GUITexture>().pixelInset.height;
 var Xk=(StartResolutions.x)/Screen.width;
 var Yk=(StartResolutions.y)/Screen.height;
 if(CalculatePositionForNewScreen){
 OffsetX=OffsetX/Xk;
 OffsetY=OffsetY/Yk;
 
 yield WaitForSeconds(0.001);
 StartResolutions.x=Screen.width;
 StartResolutions.y=Screen.height;
 }
 Can=true;
 if(CalculateScaleForNewScreen){
 GetComponent.<GUITexture>().pixelInset.width/=Xk;
 GetComponent.<GUITexture>().pixelInset.height/=Yk;
 }
 
 }
 
 
 
 
 
 
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
  • 1
  • 2
  • ›

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

10 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

Related Questions

Simple GUI question. 3 Answers

GUI Resolution Ajust 1 Answer

Scaling GUI correctly according to game window resolution? 1 Answer

How do I Scale a GUITexture or GUIText for different resolutions screen sizes on the iPhone? 1 Answer

Android GUI resize problem 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