Unity and Playmaker - How to shorten UI number and add K
In this Unity and Playmaker - How to shorten UI number and add K tutorial, I'll set up a UI for coins. Using Playmaker, I'll check once the coin count is above 999 and then add a decimal point, truncate the number an add a "K" to the coin count. (to Join my discord server add a comment and I'll re
Large coin counts look cleaner when displayed as 1.3K instead of 1300. This Playmaker tutorial builds a coin counter that listens for an add-coin event, and once the total passes 999 it converts the number to a float, shifts the decimal, rounds it, and appends a K before updating the UI.
Set up the coin counter and event
The coins already broadcast an Add Coin event when they hit the player before destroying themselves. Create an empty game object named Coin Counter and add an FSM, leaving the first state empty. Add an event called Add Coin and create a global transition for Add Coin so the FSM picks up the broadcast every time a coin is collected.
Compare the coin count
Add an Int Compare action using an int variable called coins, compared against 999. If it is equal, fire a Low Number event; if less than, also go to Low Number; if greater than, fire a High Number event. Add transitions to two new states named Low Number and High Number. This split decides whether to display the raw number or the shortened K format.
Build the Low Number state
In Low Number, use an Int Add to add 100 to coins. Then use Convert Int To String, storing the result in a new string variable called coins text, since the UI text is a string. Finally, drag the text down and add a Set Property action on the TextMesh Pro component, choosing the Text String property and feeding it the coins text variable so the on-screen count updates.
Convert and shift the decimal in High Number
In High Number, copy the Int Add to add 100 again. Then use Convert Int To Float, storing it in a new variable coins float, so the value can hold a decimal. Add a Float Operator that multiplies coins float by 0.001, storing the result back into coins float. This shifts the decimal point so 1000 becomes 1.0.
Round, convert, and append K
Use the ecosystem action Float Round To Nearest (downloadable via Playmaker Add-ons > Ecosystem, searching "float round") placed after the multiplication, rounding coins float to the first decimal place and saving back into coins float. Convert the float to a string with Float To String into coins text. Then add a Build String action with two parts: coins text plus an uppercase K, saved back into coins text. Reuse the Set Property action to push the result to the UI. Now collecting coins counts up normally, and once you reach 1000 it shows 1.3K, 1.4K, and so on.





