A few weeks ago I released a new version of my “Sprite Number Renderer” on the unity asset store. I developed this tool as I was very underwhelmed by Unity’s 3D text renderer. You can draw a font and you can change its color, that’s it. But you hardly ever see that in games, most of the times you see numbers that have style and flair and fit better into the game then plain text.
There are packages out there, most famous NGUI, but that costs a hundred dollars. I wanted some simple and light tool that could do at least numbers. So I developed this tool that pretty much does the same thing that 3D text does, which is a rendered material that the program then cuts up and selects the letter that the script wants then renders it. I wanted to make this to use for scores or other number based texts that will change over time as I was tired of plain looking scores. I wanted to make it easy to use and for me to really not do a thing after creating the tool. For this reason I spent some time making the tool automated that would add or subtract digit that would be spaced accordingly. Also to save memory gameobjects are only destroyed if another digit is attached though if you only do it a few times a frame it is ok but having a lot of destroy and create calls can really bog down the CPU. With this the object will only have 2 sub objects If going from 25 to 56 but will add one if going from 99 to 100. Making each number line up was a challenge, but I solved that accessing the spriterenderer of the digit and accessing the width from there I can instantiate the next gameobject.
I also wanted it to make this easy to use, not just for me but anyone else that used this tool. Set up is easy, develop your numbers 0-9 in whatever art program you want to use. Then in unity make it a multiple sprite spritesheet and cut and trim each number. Create an empty game object and add a Sprite Renderer and a Sprite Number. In the Sprite Number add all 10 numbers.
Now save this object as a prefab, this will be used by the main script so it does not have to be in your scene.
In scene you want add an empty gameobject and just add a number renderer component. This will render where the center point is so make sure to move it to where you want the numbers to appear. In this component replace the “Generic Number” field with the prefab you created before. The Number field will remain blank as that is used to store the numbers the tool creates.
In code create a numberrenderer variable. Then simply say .RenderNumber(aInt) and it will render whatever int you provide.
Currently the tool only takes in positive ints but could easily be expanded if needed for your application.
Tool took a while to create but saves so much time in the future and allows me to make my games look the way I want them to.
Tools like these are worth it and if you have a reoccurring problem it is usually worth the time to create in order to solve it.
Check out the package on the unity asset store Right here!