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 Kennyist · Mar 18, 2013 at 12:02 AM · c#guitimesizeint

Increase text size over time c#

HI,

I'm trying to increase text size over time, but getting an int - float error with the time part.

 public class Opening : MonoBehaviour {
     
     public GUISkin skin;
     bool title = true;
     int size = 10;
     bool closedCapOne = false;
     bool closedCapTwo = false;
     bool closedCapThree = false;
     bool closedCapFour = false;
     bool closedCapFive = false;
 
     void Start () {
         StartCoroutine(Open());
     }
     
     void Update () {
         while(title){
             size += 4 * Time.deltaTime; // Smooth time?
         }
     }
     
     IEnumerator Open () {
         CameraFade.FadeOutMain(0.1f);
         yield return new WaitForSeconds (5);
         title = false;
     }
     
     void OnGUI () {
         GUI.skin = skin;
         skin.label.fontSize = size;
         
         if(title)
         {
             GUILayout.BeginArea(new Rect(0,0,Screen.width,Screen.height));
             GUILayout.Label("Game Title");
             GUILayout.EndArea();
         }
     }
 }

How would I get around this in unity?

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

2 Replies

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

Answer by Lockstep · Mar 18, 2013 at 12:26 AM

You can make size a float and then round it to int to set the fontsize:

 float size = 10;
 
 void OnGUI () {
     GUI.skin = skin;
     skin.label.fontSize = Mathf.RoundToInt(size);

An integer and a floatingpoint number are two fundamentally different things. Intergers are the numbers { -32768 ,... -1, 0, 1, ..., 32767}, floats are saved as significant digits and an exponent. Converting from int to float is simple but you can't make an integer out of 1.5 directly. Thus you need the round to int funktion.

Comment
Add comment · Show 2 · 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 Kennyist · Mar 18, 2013 at 01:10 AM 0
Share

Thanks that worked, But of course.. Thanks to it being int, you cant have the text looking smooth.

avatar image thinkyhead_ · Feb 11, 2014 at 10:29 PM 0
Share

I'm trying to do something similar, using a GUIText that just lives in the world. It works great on the desktop and web, but on iOS it causes all the other GUIText on the screen to glitch out. Is this a known issue? (I'm posting here since others who use this trick might hit the same snag.)

avatar image
0

Answer by Owen-Reynolds · Mar 18, 2013 at 12:39 AM

Nothing to do with Unity. size (and fontSize) are ints -- can't add fractions to them. Use the rounded value:

 float size; // float will make the deltaTime line happy

 ...fontSize = (int)(size+0.5f); // rounded

The while loop in update isn't needed -- Update runs over and over already. 4*Time.deltaTime is a trick to increase by 4 points/second. Otherwise you have to guess the increase/frame that comes out to 4/second.

Comment
Add comment · Show 2 · 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 Kennyist · Mar 18, 2013 at 01:12 AM 0
Share

I was using a while so if I needed to open it again, the label wasn't some insanely high number. But then I learnt using a while inside update crashes unity.

avatar image Owen-Reynolds · Mar 18, 2013 at 04:51 PM 0
Share

Then if(title) may be what you want.

You can put a while inside Update, but it has to naturally end on its own, such as `while(i>0) { .. i--; }. It can't depend on something that might turn false after a few updates.

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

14 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

Related Questions

Multiple Cars not working 1 Answer

Any idea why my int wont display on GUI 1 Answer

buttons don't work if I use int 1 Answer

How do you change the size and color of a GUI Label in C#? 4 Answers

Changing a GUI String to read as a INT 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