0

I am working on a project in Unity and I'm trying to change my font size and color of my label. I keep getting a error on line 21... I think it's not reading the colon or something. How do I fix?

public class PlayerScore : MonoBehaviour
{
    public int points = 0;

    // Start is called before the first frame update
    void Start()
    { }

    // Update is called once per frame
    void Update()
    { }


    // score label
    private void OnGUI() 
    {
        var myFont : GUIStyle = new GUIStyle();
        myFont.fontSize = 100;
        GUI.color = Color.white;
        GUI.Label(new Rect(10, 10, 100, 100),  "Score: ", + points);
    }
}

Screenshot of code and errors here

2 Answers2

0

I think that you should do var myFont : GUIStyle; instead. After that you can modify the style in the inspector.

Try to give a better read on that page on Unity manual on how to use it accordingly: https://docs.unity3d.com/Manual/class-GUIStyle.html

THK
  • 38
  • 6
0

The colon is what's giving you the compilation error C# syntax is

var myFont = new GuiStyle();

or

GuiStyle myFont = new GuiStyle;

or

GuiStyle myFont = new();

Sorry - I know this is 6 months late but might help others coming this way (like me!)

And in order to change the label colour - this is working code:

GUIStyle style = new();
style.normal.textColor = Color.black;
Handles.Label(position, "your text", style);
Maxxx
  • 3,575
  • 1
  • 19
  • 18