Hello Guest

Author Topic: Ok, I give up! How do you load a font in code?  (Read 3846 times)

d13f00l

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Ok, I give up! How do you load a font in code?
« 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.

d13f00l

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Ok, I give up! How do you load a font in code?
« Reply #1 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!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Ok, I give up! How do you load a font in code?
« Reply #2 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.

d13f00l

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Ok, I give up! How do you load a font in code?
« Reply #3 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!