Sona Rijesh
Sona Rijesh

Reputation: 1035

Font issue in unity 3d

Hi I imported a font and using it in GUISkin for buttons. But I am getting a warning

Font size and style overrides are only supported for dynamic fonts.
UnityEngine.GUI:Button(Rect, String)

How to escape from this?

Thanks in Advance

Upvotes: 1

Views: 2761

Answers (2)

Sona Rijesh
Sona Rijesh

Reputation: 1035

private float guiDiff;

public GUIStyle scoreStyle;

// in start function

guiDiff = screenResolution.x / 480f;  (480 is my testing equipment width)

scoreStyle.fontSize = Mathf.CeilToInt(15 * guiDiff);

Its works fine for me in all device.

Upvotes: 0

Flamy
Flamy

Reputation: 313

I guess you are making for mobile platform, where dynamic fonts are not supported yet. This has been a long time problem for Unity android and iOS.

There is a simple solution to over come this, by not setting the font size in the GUI styles and set it in the font instead.

If you want the font size to change at various places, one solution is to duplicate the imported font file and change the size as many times as you want. You don't have to worry about size of files much because font files are usually in KBs.

Another solution if you don't want to duplicate fonts is by taking a font of much bigger size say arround 100. Make Text meshes with the font and control the size of the text using scale values on Text Mesh Gameobject.

Upvotes: 2

Related Questions