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 hai_2 · Nov 19, 2013 at 11:14 AM · resolutionguistylefontsizerescale

how to re-scale guiStyle property as per screen resolution?

Hi, I've used guiStyle property to display score board on the screen with background image and some text assigned with font size and padding position. I've designed based on 768x1024 screen resolution. Now I'm testing different resolutions and i did for background image to re-scale to fit as per resolution but i can't able to re-scale the font size and padding position.

GUI.Label(screenRect(0.0f,10.0f,246.0f,146.0f),m_distance.ToString() + " m\n\n" + m_score.ToString(), scoreStyle);

Here screenRect(0.0f,10.0f,246.0f,146.0f) function will re-scale 768x1024 resolution (xPosition,yPosition,objectWidth,objectHeight) to fit current screen resolution.alt text

capture.jpg (29.0 kB)
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
0
Best Answer

Answer by aeau2012 · Nov 19, 2013 at 07:49 PM

First, create a Vector3, lets call it Scale where the X will be the screen.width/your_resolution_width_Objective, the Y will be the screen.height/your_resolution_height_objective, and the Z will be 1.

Then multiply all of your GUI sizes width Scale.X , GUI sizes height Scale.Y.

For the font you will create a variable float and lets call it NewFontSize, you will multiply the currentFontSize * Scale.X, and then assign to scoreStyle.fontSize the NewFontSize, in this way the font will be scale.

This is a sample code:

 using UnityEngine;
 using System.Collections;
 
 public class ScaleAllGUI : MonoBehaviour {
 
     public float originalWidth = 768.0f;
     public float originalHeight = 1024.0f;
     private Vector3 Scale = new Vector3(0,0,0);
 
     // Use this for initialization
     void Start () {
 
         Scale.x = (float)Screen.width/originalWidth;
         Scale.y = (float)Screen.height/originalHeight; // calculate vert scale
         Scale.z = 1;
     
     }
 
     //ALWAYS MULTIPLY YOUR REAL GUI WIDTH OF EACH OBJECT * SCALE.X AND YOUR REAL GUI HEIGHT OF EACH OBJECT * SCALE.Y
     void OnGUI()
     {
         //Put all your GUI here (button,label,toggle,etc)
         if(GUI.Button(new Rect(Your_position_on_x, Your_position_on_y, The_width_of_this_gui * Scale.x, The_height_of_this_gui * Scale.y),Your_texture))
         {
         }
 
         GUI.Label(new Rect(Your_position_on_x, Your_position_on_y, The_width_of_this_gui * Scale.x, The_height_of_this_gui * Scale.y),Your_texture);
 
 
         //Now for the font one, we create a variable and we multiply the fontSize of the style * Scale.x
         float NewFontSize = Scale.x * current_font_size_of_your_style;
         scoreStyle.fontSize = (int)NewFontSize;
 
         GUI.Label(screenRect(0.0f,10.0f,246.0f * Scale.x,146.0f * Scale.y),m_distance.ToString() + " mnn" + m_score.ToString(), scoreStyle);
 
 
     }
 
 }
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

18 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Font size in GUI Label changes between editor and build 1 Answer

How do i change the fontSize of a displayed message? 1 Answer

OnGUI Button 1 Answer

Is there any way to rescale a terrain map? 4 Answers

GUILayout.Label - WordWrap and FontSize issue. 2 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