Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Writing Text with Sprites

Discussion in 'Assets and Asset Store' started by ma.parizeau, Nov 24, 2014.

  1. ma.parizeau

    ma.parizeau

    Joined:
    Mar 21, 2010
    Posts:
    116
    Hi everyone,

    I wanted multicolored font for my game. I just finished a script and I taught I would share it with you guys since I had a lot of problem finding something like this. (see screenshot)

    If you want to use sprites instead of a font to write text in your game (Hud, Menu, etc.) then download the package. No matter how many time you use it in your scene, if you are using the same sprite sheet, will only use 1 draw call.

    What you need:
    1. A Sprite Sheet with all of your characters.
      1. Rename each sprite with the ASCII decimal code (yes it's long but no pain no beautiful "font"!)
        1. Adjust each box in order to leave enough space in between characters.
          1. Example: the I, J, !, coma, etc. will need more space on the right and a bit a the left in order to look properly space. (Yes it's trial and error here...) Look at my GameFont.psd file for an example.
    2. To see how it works, use the Image prefab (to use on a Canvas - Unity 4.6)
      1. You can use it on a regular GameObject (for those with Unity 4.5 and less), you just need to change the prefab in the resources folder for a GameObject with a regular SpriteRenderer.
    3. On your script WriteText.cs, add all of your sprites to Font[] field (yes it's long but hard work is always fulfilling!... lol)

    How it works;
    1. Type your text in the Text field.
      1. It's single line only. Yes in the code, I started to try an implement multiple lines... but no need for me at this point. So if you want to give it a try and share with everyone... go ahead :)
    2. Set the Font Size: 1.0f = Normal size (The spacing will automatically adjust as per the size.)
    3. If you want to add or subtract spacing between the characters, set Font Spacing
    4. ignore Line Spacing. Why? See point 1.1 ;)
    See the screenshot Image 1.png for the result.

    Hope you enjoy this simple but useful (at least for me) script.
     

    Attached Files: