Unity Useless GuiText fontsize. Im so mad.

Hi folks.

I’m Googling all day searching for a function in c# that change guiText sizes acording to resolution.

I’m making a quizz, but the text’s are getting distorced and stuff. So i found this:

    public Vector2 offset;
    public float ratio = 10;
    // Use this for initialization
    void Start () {
    }
    // Update is called once per frame
    void Update () {
    }
    void OnGUI(){
        float finalSize = (float)Screen.width/ratio;
        guiText.fontSize = (int)finalSize;
        guiText.pixelOffset = new Vector2( offset.x * Screen.width, offset.y * Screen.height);
    }

But doesn’t work as expected. How you guys solve this guiText font size problem?

So, some things.

a) guiText is a component on a GameObject. It’s pretty unrelated to the OnGUI() function, and you don’t usually change guiText from inside an OnGUI(). Instead, inside OnGUI() you’d call the various GUI APIs to draw your GUI.

b) To change the size of a fontyou need to have the font marked as dynamic when it’s imported. If your font is dynamic, and you move your code from OnGUI() to Update() I’d expect it to work. (Except that I have no idea what your offset code is trying to do, since it’s never given a value, so must be set in the inspector.)

c) If you are building your GUI inside OnGUI() using the GUI components, then you’ll need to read up on GUISkin and GUIStyle.

Hi, thanks for the reply.

My guiText are dynamic. Here it is some code we write (but he don’t wordwrap the text, i do manually -_-):

		//GameObject.FindWithTag("Pergunta").guiText.fontSize = Screen.width/28;
		GameObject.FindWithTag("OpcaoA").guiText.fontSize = Screen.width/30;
		GameObject.FindWithTag("OpcaoB").guiText.fontSize = Screen.width/30;
		GameObject.FindWithTag("OpcaoC").guiText.fontSize = Screen.width/30;
		GameObject.FindWithTag("OpcaoD").guiText.fontSize = Screen.width/30;
		GameObject.FindWithTag("Proxima").guiText.fontSize = Screen.width/30;
		GameObject.FindWithTag("Pergunta").guiText.color = new Color(235,235,235,255);

		//Posicionando aos objetos
		GameObject.FindWithTag ("Titulo").transform.position = new Vector2(0.5f,0.99f);
		GameObject.FindWithTag ("Pergunta").transform.position = new Vector2(0.02f,0.90f);
		GameObject.FindWithTag ("OpcaoA").transform.position = new Vector2(0.05f,0.65f);
		GameObject.FindWithTag ("OpcaoB").transform.position = new Vector2(0.05f,0.5f);
		GameObject.FindWithTag ("OpcaoC").transform.position = new Vector2(0.05f,0.35f);
		GameObject.FindWithTag ("OpcaoD").transform.position = new Vector2(0.05f,0.2f);
		GameObject.FindWithTag ("Proxima").transform.position = new Vector2(0.80f,0.06f);