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 stevenp · Mar 15, 2012 at 05:04 AM · iphoneguitextfontfontsize

Simple way to change GUIText font size

Hi guys!

Is there no simple way to change GUIText font size? Currently the text size looks nice in iPhone screen but when it comes to Retina Display, it becomes very small. I've looked for solutions but it seems GUIText.fontSize is only for dynamic fonts. Is there any other way to adjust the font size from the script without having to create custom font? Thanks in advance! =)

Edit: To make things clearer, these all are the steps I've done:

Script part:

 private var infoText:GUIText;
 private var theFont:Font;
 var fonts:Font[];

 function Awake(){
     infoText = GameObject.Find("Info").GetComponent(GUIText);
     infoText.enabled = false;
 }
 
 function OnGUI(){
     if(iPhoneGeneration.iPhone3GS){
        theFont = fonts[0];
        }else if(iPhoneGeneration.iPhone4){
        theFont = fonts[1];
     }
 }
 
 function PostScore(){
 .
 .
 if(hs_post.isDone){
    infoText.text = "Score uploaded";
    infoText.font = theFont;
    infoText.enabled = true;
    }
 }
 
 function CheckUsername(){
    if(userName.Length == 0){
    infoText.enabled = true;
    infoText.text = "Please put your username";
    infoText.font = theFont;
    }
 }

Those are where I access the "infoText" from the script

For the settings:

alt text alt text alt text alt text

I hope I didn't miss anything.

Comment
Add comment · Show 9
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 syclamoth · Mar 15, 2012 at 05:24 AM 0
Share

Just import a custom font. Chances are it'll look better anyway.

avatar image JDPennock · Mar 15, 2012 at 05:36 AM 0
Share

Yeah I have the same problem with various android devices and the best way I have found is to import a custom font for each.

avatar image stevenp · Mar 15, 2012 at 06:20 AM 0
Share

This is what I get for trying to import custom font

"Dynamic Fonts are not supported on this build platform"

Apparently, the documentation says "Dynamic fonts are currently only supported on Desktop platforms ($$anonymous$$ac and Windows)." so I guess it can't be used for mobile device, no?

avatar image JDPennock · Mar 15, 2012 at 06:32 AM 0
Share

Ok for whatever font you are going to use, you are going to have to make multiple copies of it for every font size that you need. So say your font is called Arial and you need a version in 16 point for iPhone and in 24 point for Retina Displays. $$anonymous$$ake two copies of that font. Name one something like Arial-iPhone and the other Arial-Retina. Drag both of them into your project folder. Then click on the first one in the project view and you should see the "true type Font Importer" component in the inspector set the font size to 16 or whatever you need there and then change the Character from the default of dynamic to whatever is supported by your platform likely "ASCII default set" Do the same for your other font but set it to the other size that you need. That should take care of that "Dynamic Fonts are not supported on this build platform" error ...that is unless somewhere in your code or one of your GUIStyles is trying to set one of those fonts to a different size.

avatar image JDPennock · Mar 15, 2012 at 06:52 AM 0
Share

This was sort of already covered in this answer: http://answers.unity3d.com/questions/20599/how-do-you-increase-gui-text-font-size-.html

And this link to docs could be helpful: http://unity3d.com/support/documentation/Components/class-Font.html

Show more comments

4 Replies

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

Answer by JDPennock · Mar 15, 2012 at 07:38 PM

Is it working for you now?

OnGUI is called multiple times every frame so its not the best idea to put the check in there. This should work a little better:

 private var infoText:GUIText;
 private var theFont:Font;
 var fonts:Font[];
 
 function Awake(){
     infoText = GameObject.Find("Info").GetComponent(GUIText);
     infoText.enabled = false;
 
     if(iPhoneGeneration.iPhone4){
        infoText.font = fonts[1];
     }
     else{
        infoText.font = fonts[0];
     }   
 }
     
 function PostScore(){
 .
 .
 if(hs_post.isDone){
    infoText.text = "Score uploaded";
    infoText.enabled = true;
    }
 }
 
 function CheckUsername(){
    if(userName.Length == 0){
    infoText.enabled = true;
    infoText.text = "Please put your username";
    }
 } 
Comment
Add comment · Show 3 · 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 JDPennock · Mar 15, 2012 at 07:50 PM 0
Share

you could also add an extra variable and an enum to make you code a little more clear and give you the ability to switch between the two fonts in the inspector easily.

private var infoText:GUIText; private var theFont:Font; var fonts:Font[]; enum $$anonymous$$yFonts { Iphone = 0, Retina = 1 } var CurrentFont : $$anonymous$$yFonts;

function Awake(){ infoText = GameObject.Find("Info").GetComponent(GUIText); infoText.enabled = false;

 if(iPhoneGeneration.iPhone4){
    CurrentFont = fonts[$$anonymous$$yFonts.Retina];
 }
 else{
    CurrentFont = fonts[$$anonymous$$yFonts.Iphone];
 }   

}

function PostScore(){ . . if(hs_post.isDone){ infoText.text = "Score uploaded"; infoText.font = CurrentFont; infoText.enabled = true; } }

function CheckUsername(){ if(userName.Length == 0){ infoText.font = CurrentFont; infoText.enabled = true; infoText.text = "Please put your username"; } }

avatar image JDPennock · Mar 15, 2012 at 07:52 PM 0
Share

sorry that is hard to read, I'm not quite sure how to make code show up correctly in the comments here.

avatar image stevenp · Mar 16, 2012 at 03:43 AM 0
Share

That works, thanks a lot for bearing with me xD I didn't expect that changing text size only applies for Dynamic Fonts and quite a tedious way to resize a text here =(

avatar image
0

Answer by stevenp · Mar 16, 2012 at 03:22 AM

Ok, that works. But why I can't mark the answer!? I can't even comment on the answer @_@

Edit: Ok, that was weird, took like 1/2 hour to be able to mark it.

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 maspi · Jun 25, 2012 at 07:04 PM

Seems that Unity 4 (probably in August 12) will solve the problem. One little but great feature: "* Dynamic fonts on all platforms with HTML-like markup" see: http://www.marketwire.com/press-release/the-next-generation-of-the-unity-game-engine-unveiled-1670512.htm hopefully …

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 maspi · Jun 25, 2012 at 07:06 PM

Seems that Unity 4 (probably in August 12) will solve the problem. Just one little but great feature of all: " Dynamic fonts on all platforms with HTML-like markup" see: http://www.marketwire.com/press-release/the-next-generation-of-the-unity-game-engine-unveiled-1670512.htm hopefully …

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

7 People are following this question.

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

Related Questions

Changing the font size of GUIText (on Unity iPhone)? 1 Answer

Display two byte character by using GUIText.(Unity iPhone) 1 Answer

GUI Text as a Button? 1 Answer

Jagged and pixelated fonts in text mesh 3d (iphone) 4 Answers

Unity iPhone scene transition on Tap of GUIText 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