0

I have been working on a game recently and It's going very good. Today I started working on the menu and I created a button, but there is one problem, I have no idea how to change the size of the font :/

Here is the script:

The Code

Fattie
  • 27,874
  • 70
  • 431
  • 719
  • Possible duplicate of [Change text of Unity 4.6 UI button](http://stackoverflow.com/questions/27510743/change-text-of-unity-4-6-ui-button) – Fattie Feb 09 '16 at 20:40
  • This is a duplicate to close, just FYI you can NOT use the extremely old "ongui" system, Unity are removing it and it is no longer supported. Good news the ordinary Unity.UI system is incredibly easier to use https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/the-new-ui Here is a full tutorial (1) click add canvas (2) click add button. You're done – Fattie Feb 09 '16 at 20:43

2 Answers2

0

Pass a GUIStyle into the function and set the font size inside the GUIStyle.

Somthing like this should really work.

using UnityEngine;
using System.Collections;

public class FontSizeExample : MonoBehaviour 
{

    GUIStyle smallFont;
    GUIStyle largeFont;

    void Start () 
    {
        smallFont = new GUIStyle();
        largeFont = new GUIStyle();

        smallFont.fontSize = 10;
        largeFont.fontSize = 32;
    }

    void OnGUI()
    {
        GUI.Label(new Rect(100, 100, 300, 50), "SMALL HELLO WORLD", smallFont);
        GUI.Label(new Rect(100, 200, 300, 50), "LARGE HELLO WORLD", largeFont);
    }
}

source

Community
  • 1
  • 1
phenxd
  • 689
  • 4
  • 17
  • I get an error saying: "Unexpected Token: GUIStyle" – Nikola Zagorac Feb 09 '16 at 20:18
  • Maybe you need to do some imports? – phenxd Feb 09 '16 at 20:20
  • hi @phenxd although this is a well-written answer, pls do not answer many-times duplicates. There is a huge problem on SO of Unity3D clutter of ***very easy questions, which already have full answers***. I suggest it's best just to click Dupe. – Fattie Feb 09 '16 at 20:41
0

Ok so I researched the GUIStyle a bit and I did this:

var guiStyle : guiStyle;

and then I did

if(GUI.Button(Rect(playX, playY, sizePlayX, sizePlayY), "Play", guiStyle)) { code }

And I got a new thing in the inspector of the script where I could change everything, the font size, color only problem was that the border disappeard... Anyone know how to fix this ?

  • If you're still facing problems, you'd be best served to write a new question for this - most people don't look through the answers to see if there are still lingering questions. – Serlite Feb 10 '16 at 15:59