Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

GUI Text size

Discussion in 'Scripting' started by Sweex, Jun 27, 2014.

  1. Sweex

    Sweex

    Joined:
    Jan 26, 2014
    Posts:
    25
    Hello! Is there any way to adjust GUI Text size to match screen size. I have GUIText with size of 20, and it matches my phone screen, but when I install it on device with lower screen size, like 3.8inch it is still big and all over the screen.
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    You can script it to resize itself based on Screen.width, but honestly I would sooner recommend that you use 3D Text instead, which does that automatically. (Also, support for the "GUI Text" object will be going away at some point, as it is being replaced with the uGUI system.)
     
  3. katsuragi545

    katsuragi545

    Joined:
    Jun 25, 2014
    Posts:
    38
    You could adjust the GUI Text size in the Start() function by determining the screen size using Screen.width and Screen.height - this is what I do in my mobile games. Something like this:

    Code (CSharp):
    1.  
    2. sh = Screen.height;
    3. sw = Screen.width;
    4. if(sh <= 320)
    5. {
    6.        guiText1.fontSize = 20;
    7. }
    8. else if(sh > 320 && sh <= 480)
    9. {
    10.        guiText1.fontSize = 40;
    11. }
    12. else if(sh > 480 && sh <= 540)
    13. {
    14.        guiText1.fontSize = 60;
    15. }
    16. else if(sh > 540 && sh < 720)
    17. {
    18.        guiText1.fontSize = 80;
    19. }
    20. else{
    21.      guiText1.fontSize = 100;
    22. }
    23.  
     
    Last edited: Jun 27, 2014
  4. Sweex

    Sweex

    Joined:
    Jan 26, 2014
    Posts:
    25
    Thank you guys! I used 3D Text but it's also nice to know that method also :)