Search Unity

Javascript text being to small on Phones

Discussion in 'Scripting' started by byro210, Jun 17, 2014.

  1. byro210

    byro210

    Joined:
    Feb 18, 2014
    Posts:
    121
    I have a mobile game on the Android store, but some phones the Text seems to be to tiny for them to read - A Samsung Galaxy S4 & A HTC One, Could anyone help with whats wrong with this code
    Code (CSharp):
    1.  
    2.  
    3. var textStyle: GUIStyle;
    4.  
    5.  
    6. function Start () {
    7.  
    8. //Preference Stat Handling Interface
    9. PlayerPrefs.SetString("News1", "(Welcome to Idle Rpg Beta Start a New Game, Theres current only 17 maps but)");
    10.                                                                                                                      //Here
    11. PlayerPrefs.SetString("News2", "(Sorry about all these bugs but thankyou for helping spot them)");
    12. PlayerPrefs.SetString("News3", "(New Charm Shop they give Abilities! fixed now i think haha)");
    13. PlayerPrefs.SetString("News4", "(Why not explore Faerie Forest Today)");
    14.  
    15. }
    16.  
    17.  
    18. function Update () {
    19.  
    20. }
    21.  
    22. function OnGUI ()
    23. {
    24.     GUI.Label (new Rect (Screen.width/33.95f,Screen.height/3.50f, Screen.width/1.50f,Screen.height/10.2f),String.Format("{0}",PlayerPrefs.GetString("News1"), textStyle));
    25.  
    26.     GUI.Label (new Rect (Screen.width/2.95f,Screen.height/2.65f, Screen.width/1.50f,Screen.height/10.2f),String.Format("{0}",PlayerPrefs.GetString("News2"), textStyle));      
    27.  
    28.     GUI.Label (new Rect (Screen.width/33.95f,Screen.height/2.25f, Screen.width/1.50f,Screen.height/10.2f),String.Format("{0}",PlayerPrefs.GetString("News3"), textStyle));
    29.  
    30.     GUI.Label (new Rect (Screen.width/2.95f,Screen.height/1.95f, Screen.width/1.50,Screen.height/10.2f),String.Format("{0}",PlayerPrefs.GetString("News4"), textStyle));
    31.      }
    32.  
    Its happening with Text on every scene not just this 1 Scene
     
  2. byro210

    byro210

    Joined:
    Feb 18, 2014
    Posts:
    121
    Anyone?
     
  3. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    You don't appear to be changing the font size anywhere in your code, that's your problem. I know your labels vary in size, but the content doesn't.

    Code (CSharp):
    1.  
    2.     // c# example
    3.     void OnGUI() {
    4.         GUIStyle g = GUI.skin.GetStyle("label");
    5.         g.fontSize = (int)(20.0f + 10.0f * Mathf.Sin(Time.time));
    6.         GUI.Label(new Rect(10, 10, 200, 80), "Hello World!");
    7.     }
    8.  
     
  4. byro210

    byro210

    Joined:
    Feb 18, 2014
    Posts:
    121
    Im doing the game in JavaScript though ive done no C# at all :( - Hmm and yeah but the 10, 10, 200, 80 - does not resize it on every phone it might be huge on small phones which is a problem :S ?
     
    Last edited: Jun 19, 2014
  5. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    My little code example was meant to show you the missing piece which is how to tell Unity to change the size of the dynamic font. I think your code with the labels being sized according to the screen size is still needed. I did not mean to imply that you should cut and paste my code directly into your game.
     
  6. byro210

    byro210

    Joined:
    Feb 18, 2014
    Posts:
    121
    I didn't Cut and Paste your code - I was stating that I had tried that before but - then if a phone to small for the writing is there the writing just goes off* the screen.? But I don't see why big phones the text is too tiny to read anyway
     
    Last edited: Jun 19, 2014
  7. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    So, the fonts get rendered at a certain size, and that is related to the number of pixels needed to show the character. On large tablets with high-res screens, these pixels are small, and so the text looks small. To compensate, you need to make the font larger, using the GUIStyle.fontSize API, which is why I posted some example code. Can you post the code that you have and which does not work. If you are using the GUIStyle.fontSize API, and that does not change the size of the text on the display, then something is obviously wrong.