Customizing and Resizing GUI Text

I would like to create a few boxes to be placed on the Menu Screen, each of which contain different text. I’d like to set a certain font size, color and type.

The problem with using GUI Text is that although I can customize it nicely, I’m not sure how to resize it based on different screen resolutions. I’ve used the Rect function for GUI Textures, but I’m not sure what to use for GUI Text.

What is the best way to do this? Would I use GUI Styles? I’m scripting in C, but the Unity documentation only has examples in Java.

An example menu would be:

Play
Tutorial
Upgrades
About

Thank you!

i’ve been using this for guitextures & guitexts (code is mostly from unity answers),
this one is not the latest version though it might had some problems in HD…

using UnityEngine;
using System.Collections;

// guitext & guitexture autoscaler

public class GUIScaler : MonoBehaviour
{
    public float scaleAdjust = 1.0f;
    private float scaleFix = 1.4f;

    private const float BASE_WIDTH = 1280;
    private const float BASE_HEIGHT = 800;

    void Start()
    {
        float _baseHeightInverted = 1.0f/BASE_HEIGHT;
        float ratio = (Screen.height * _baseHeightInverted)*scaleFix*scaleAdjust;
        //Debug.Log ("scale ratio:"+ratio);

        if (GetComponent<GUITexture>()!=null)
        {
            GUITexture _guiTextureRef = GetComponent<GUITexture>();
            _guiTextureRef.pixelInset = new Rect(_guiTextureRef.pixelInset.x* ratio, _guiTextureRef.pixelInset.y* ratio, _guiTextureRef.pixelInset.width * ratio, _guiTextureRef.pixelInset.height * ratio);
        }else{
            if (GetComponent<GUIText>()!=null)
            {
                GetComponent<GUIText>().pixelOffset = new Vector2(GetComponent<GUIText>().pixelOffset.x*ratio, GetComponent<GUIText>().pixelOffset.y*ratio);
                GetComponent<GUIText>().fontSize = (int)(GetComponent<GUIText>().fontSize*ratio);
            }
        }
    }
}
1 Like

Thank you!

What does _baseHeightInverted do? (what is its value and where does it come from?) And what is the reason for the 1.0f and 1.4f values for scaleAdjust and scaleFix respectively?

I think it was based on this, there was another similar in answers somewhere…

I think scalefix was just quick solution to adjust size manually…cant remember why : )