2D Toolkit Forum

2D Toolkit => Support => Topic started by: d13f00l on December 06, 2015, 03:23:20 am

Title: Ok, I give up! How do you load a font in code?
Post by: d13f00l on December 06, 2015, 03:23:20 am
I have a working font prefab.
I can use the font in the GUI editor.  I want to assign the font in code.

GameObject font = Resources.Load ("gui/HardpixelFontdata") as GameObject;
tk2dFontData fontdata = font.GetComponent <tk2dFontData>();

And then on an existing.. tk2dTextMesh object

tk2dTextMesh textmesh = option.GetComponent <tk2dTextMesh>();
textmesh.font = fontdata;

The text is invisible!  If I don't set the font in code, it's fine.  No errors are outputted to the console.
Title: Re: Ok, I give up! How do you load a font in code?
Post by: d13f00l on December 06, 2015, 03:29:21 am
Nevermind.  It's doing exactly what I told it to do.  Bit of a scaling issue throws it off the screen!
(http://i.imgur.com/ueWXlBS.png)
Title: Re: Ok, I give up! How do you load a font in code?
Post by: unikronsoftware on December 06, 2015, 12:09:58 pm
I'm not sure why this isn't working - please post a repro case in the private support forum and I'll take a look at it.
Title: Re: Ok, I give up! How do you load a font in code?
Post by: d13f00l on December 06, 2015, 07:10:45 pm
It's fine, it's not invisible.  It's off-screen, because my scaling isn't right for the font.  Disregard!