Hello Guest

Author Topic: Using Unity's GUIText with 2D Toolkit  (Read 48718 times)


  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Using Unity's GUIText with 2D Toolkit
« on: August 22, 2013, 12:09:53 pm »
If you would like to use Unity's GUIText for dynamic fonts with 2D Toolkit, the bad news is you can't. The good news is there is a pretty straightforward solution to this using the Unity Text Mesh (3D Text) component.

To set-up the font
1. Create a dynamic font as you would normally.
2. Create a new material.
3. Assign 2DToolkit/GUIText shader to it. You can download the shader on this post.
4. Drag the Font Texture from the dynamic font to the "Font Texture" slot.

And to create a text mesh
1. Hierarchy > Create > 3D Text.
2. You will need to change Character Size. This depends on the size of your camera / resolution. Unity uses 10 pixels per meter, so if your tk2dCamera is set to 10 pixels per meter, you wont have to change any settings here. Scale this value appropriately. 20 pixels per meter = 0.5, 5 pixels per meter = 2. If you're using ortho size, then the scale will be
20 / native resolution height. Note: Thats a 20, not 2.0!
For the UI Mask demo scene in 2D Toolkit 2.2, the character size should be 0.03125 (20 / 640 native height).
3. Drag the override material you set up earlier to the material slot.

You can now use this as a drop in replacement for tk2dTextMesh if you need to. It will clip properly with the tk2dUIMask, etc.