C# changing font for GUI.Button within a C# script

I have set the font size to 40 in “style.fontSize = 40;” However, no changes are being made. Help or guidance will be appreciated.

using UnityEngine;
using System.Collections;
//new using
using UnityEngine.SceneManagement;

public class MainMenu : MonoBehaviour {
    public GUISkin skin;
    public GUIStyle GUIStyle;
    public Font f;
    void OnGUI ()
    {


        GUI.skin.font = f;
        GUI.skin = skin;
        GUIStyle style = new GUIStyle();
        style.fontSize = 40;
        GUI.Label (new Rect (Screen.width/3, Screen.height/8, 1000, 1000), "Ice Crew");
        if(PlayerPrefs.GetInt("Level Completed") > 0)
           {
            if(GUI.Button(new Rect (Screen.width/2.5f,Screen.height/1.5f,200,100), "Play"))
        {   
            SceneManager.LoadScene(PlayerPrefs.GetInt("Level Completed"));
        }
        }
        if(GUI.Button(new Rect (Screen.width/2.5f,Screen.height/2.5f,200,100), "New Game"))
        {   
            PlayerPrefs.SetInt("Level Completed", 0);
            SceneManager.LoadScene(1);
        }
    }   
}

line 17

You never tell any of your buttons to actually use that style anywhere.

With that said - just switch to the new UI system and make a prefab for each of your buttons :slight_smile:

1 Like

The specific issue you’re having in this case is that you create this GUIStyle but never use it anywhere.

But the more important, fundamental issue you’re having is that you’re using the old, deprecated UI system, and should learn the new system instead. It’s better-looking, easier to use, performs better, and more. The only reason to use the old UI system is legacy, that is, because you’ve been working on the same game since before 2013 (when the new system came out) and it’s too much trouble to change now… which I surmise is not the case here. If you’re looking for UI tutorials for Unity, you should make sure to use tutorials that specify they are for Unity 4.6 or higher.

1 Like

thank you I will check out the new system :slight_smile:

thank you I will head over to that link and check out the new system :slight_smile: