Unity GUI Font Size changes with the screen resolution Problem
I am working on a project and now I have a problem . The problem is the font size. The font size is OK inside the Unity but it is really small when I play the game on a real Android device .
My Canvas has 2 text and 1 image .
I created a empty game object to hold that text.
Here is the code attached to empty game object :-
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Text_Script : MonoBehaviour
{
public Text My_Text_1 ;
public Text My_Text_2 ;
// Use this for initialization
void Start ()
{
My_Text_1.text = "Hello";
My_Text_2.text = "World";
}
// Update is called once per frame
void Update ()
{
}
}
Here are the images :-
Inside Unity
Inside a Android Device (here I uploaded the image from BlueStacks , I didn't use my mobile)
So why this is happening ?
I tried this :-
function Start()
{
var myText = GetComponent(GUIText);
// 50 is the fontsize you want to use
myText.fontSize = Mathf.Min(screen.height,screen.width)/50;
}
but I don't know where to put and on which object should I put those code And I am using Unity 5 and that code is for Unity 4.x .
I don't want to scale the font for a large size as explained in YouTube video (https://www.youtube.com/watch?v=_9mOh7_xX2o) (I don't think this is a good method)
So is there any ways to change the font size according to the screen size and resolution .
Please help me
Thanks:)
Answer by LazyElephant · Jan 10, 2016 at 08:14 AM
You don't need to fix this in script. If you position the anchors for your Text objects properly, your text will scale based on the screen resolution. In fact, on that video description, he links to another video that explains how to do it with the new GUI elements.
Your answer
Follow this Question
Related Questions
Using Japanese in my game 1 Answer
TextMeshPro Set Alpha Color 0 Answers
UTF-8 UI Text problem 2 Answers
Modals for 3D Objects/Environment 0 Answers