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 pulkit8.mahajan · Apr 02, 2014 at 07:33 AM · textmobile

How to set up Same sized text on all screens?

So i have been looking around a lot, and I can't find a good solution that doesn't require payment. I'm looking for a way to set the font size to a certain size that will be the same on all devices. Ex: My current font size works well on the gs4, but on my friends gs2, it is way too big. I read something about setting the font to Unicode, but I can't figure out how to do that. Please Help!

Comment
Add comment · Show 2
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 HariKrishnan · Apr 02, 2014 at 10:15 AM 0
Share

in script you will set the screen resolution.below method using to Screen.SetResoltion(480,800,true); Like that can u . can u find ur gs4 resolution size to fix in ur script.

avatar image pulkit8.mahajan · Apr 02, 2014 at 11:15 PM 0
Share

But will this work on all devices? I don't want it to work on just one.

2 Replies

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

Answer by Scribe · Apr 03, 2014 at 12:47 AM

This should work on the devices you mentioned:

 private var resolutionIndex : int = 0;
 private var screenRes : Resolution;
 private var resChanged : boolean = true;
 private var displayDPI : float;
 private var mmToInch : float = 25.4;
 private var fontSize : float;
 
 var textHeight : float = 10; //the desired text height in mm
 
 function ResolutionUpdate(){
     Screen.SetResolution(screenRes.width, screenRes.height, true);
     if(Screen.dpi == 0){
         Debug.Log("Could not find the dpi of this display.");
         displayDPI = 300;
     }else{
         displayDPI = Screen.dpi;
     }
     resChanged = true;
 }
 
 function ActualToPixel(){
     return (displayDPI*textHeight)/mmToInch;
 }
 
 function Start(){
     screenRes = Screen.currentResolution;
     ResolutionUpdate();
 }
 
 function Update(){
     ResolutionUpdate();
 }
 
 function OnGUI(){
     GUI.skin.label.fontSize = ActualToPixel();
     GUI.Label(Rect(0, 0, Screen.width, Screen.height), "AaBbCcDdEeFfGgHhIiJj");
     
     GUI.skin.label.fontSize = 20;
     GUI.Label(Rect(0, Screen.height-50, 200, 50), textHeight.ToString());
 }

I tested this first on my laptop however my laptop doesn't seem to supply a value for Screen.dpi so it doesn't work there. I tested this on my Android GS3 and it looks like it works in producing a font size to equal a certain number of millimetres in height so I am hoping/assuming it will do the same for any device that it can get a Screen.dpi value from.

Scribe

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 pulkit8.mahajan · Apr 03, 2014 at 02:07 AM 0
Share

Where should I attach this script?

avatar image Scribe · Apr 03, 2014 at 02:59 AM 0
Share

In the script I change the globally used GUI.skin so if you take out line 38 GUI.skin.label.fontSize = 20; then anything that uses the default style will be resized accordingly, then you can just stick this wherever you want, the camera or a fontsize$$anonymous$$anager gameobject or something.

avatar image Scribe · Apr 05, 2014 at 02:44 PM 0
Share

If your question has been answered I'd appreciate if you marked it as such, or please explain any problems you are still having and I can try to help!

Scribe

avatar image pulkit8.mahajan · Apr 05, 2014 at 04:31 PM 0
Share

I'm testing it out now, but I have been out of the house for a few days. I will get back to you if I see any problems.

avatar image pulkit8.mahajan · Apr 05, 2014 at 04:45 PM 0
Share

So, right now, just testing it out on my phone, it's too big. Is there any fudge factor to play around with? The text should be half this size

Show more comments
avatar image
0

Answer by arkariarn · Apr 02, 2014 at 11:45 PM

hmm, just an idea but maybe you can check for the screen resolution and change the font size of the gui accordingly, or change the gui.skin itself to a gui.skin with a smaller fontsize. your code would be something like this: if(screen.width < 400){ //change gui.skin or fontsize if possible}

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

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

Related Questions

How should I go about proper GUIText scaling for mobile devices? 0 Answers

How do I make a mobile game in all languages and able to switch text in different languages in the game and sell on google play and Apple Store 2 Answers

High score local [Android] 1 Answer

TMP text dosent show up in android. 0 Answers

How can you delete the beginning or middle of a content from a text field without having to delete all the content from the end? 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