Damage Numbers Pro

Add number and text popups to your game.
Easy to Use
– Supports 2D, 3D and GUI
– Works in Every Render Pipeline

Feel free to ask for support.
Discord https://discord.gg/nWbRkN8Zxr
Email
ekincantascontact@gmail.com

Store Link:


Demo:


Tutorial:
[Image]

First you need to create a new damage number.
Click on the + symbol in the Hierarchy window.

Mesh: 2D or 3D Worldspace (no canvas)
GUI: Canvas Rectspace





[Image]

I recommend saving your damage numbers as prefabs in a shared folder.
Makes access and organization easier.

If you save the damage number in a scene instead, keep it's gameobject disabled.

[Image]

You can customize everything within the damage number inspector.
Use the tab buttons to navigate through the settings.




[Image]

Everything is structured into features.
Click on a feature to toggle it.

The [R] button resets the feature and the [?] button displays hints.




[Image]

You can use preset buttons to customize faster and find new possibilities.

You can also edit the material and text mesh pro settings.
Simply click the tab buttons to view them.




[Image]

If you picked the Mesh version you will see the popup in the editor.
The GUI version has to be in a canvas to render.

Visual settings (text, material & tmp) will update while editing.
For other settings you need to play your game to view them.

Hint:
To tweak other settings you can edit the prefab at runtime.
Spawned popups will use the latest prefab settings.

Examples:
The script below will spawn a random number between 0 and 100 on leftclick.
using UnityEngine;
using DamageNumbersPro;

public class Example : MonoBehaviour {

    //Assign prefab in inspector.
    public DamageNumber numberPrefab;

    void Update()
    {
        //On leftclick.
        if(Input.GetMouseButtonDown(0))
        {
            //Spawn new popup at transform.position with a random number between 0 and 100.
            DamageNumber damageNumber = numberPrefab.Spawn(transform.position, Random.Range(1,100));
        }
    }
}
[Image]

Simply assign a damage number prefab to the numberPrefab variable.



[Image]

Leftclicking will now spawn a random number between 1 and 100.


The script below will spawn a random number between 0 and 100 on leftclick.
Popups will be children of rectParent with an anchored position of (0,0).
using UnityEngine;
using DamageNumbersPro;

public class Example : MonoBehaviour {

    //Assign prefab in inspector.
    public DamageNumber numberPrefab;
    public RectTransform rectParent;

    void Update()
    {
        //On leftclick.
        if(Input.GetMouseButtonDown(0))
        {
            //Spawn new popup with a random number between 0 and 100.
            DamageNumber damageNumber = numberPrefab.SpawnGUI(rectParent, Vector2.zero, Random.Range(1,100));
        }
    }
}
[Image]

Simply assign a damage number prefab to the numberPrefab variable.



[Image]

Leftclicking will now spawn a random number between 1 and 100.



Basics:
First you reference your prefab with a public DamageNumber variable or Resources.Load<DamageNumber>(...).
Then you call the Spawn(...) function (see below) on the prefab's DamageNumber component to spawn a new popup.
If you are using the GUI version, you also need to call one of the gui functions (see below).

The Spawn(...) function returns the spawned damage number's component.
You can change every setting and use several utility functions (see below) on the returned component.


Namespace:
using DamageNumbersPro;

Spawn Functions (Mesh):
//Basic:
DamageNumber damageNumber = numberPrefab.Spawn();
DamageNumber damageNumber = numberPrefab.Spawn(Vector3 position);
DamageNumber damageNumber = numberPrefab.Spawn(Vector3 position, Transform followedTransform);

//Spawn and Set Number:
DamageNumber damageNumber = numberPrefab.Spawn(Vector3 position, float number);
DamageNumber damageNumber = numberPrefab.Spawn(Vector3 position, float number, Transform followedTransform);

//Spawn and Set Text:
DamageNumber damageNumber = numberPrefab.Spawn(Vector3 position, string leftText);
DamageNumber damageNumber = numberPrefab.Spawn(Vector3 position, string leftText, Transform followedTransform);

Utility Functions:
DamageNumber damageNumber = numberPrefab.Spawn(Vector3 position);

//Set Followed Target:
damageNumber.SetFollowedTarget(Transform followedTransform);

//Set Color:
damageNumber.SetColor(Color color);

//Set Gradient Color:
damageNumber.SetGradientColor(VertexGradient vertexGradient);
damageNumber.SetGradientColor(Color topLeft, Color topRight, Color bottomLeft, Color bottomRight);

//Set Random Color:
damageNumber.SetRandomColor(Color from, Color to);
damageNumber.SetRandomColor(Gradient gradient);

//Font Material:
damageNumber.SetFontMaterial(TMP_FontAsset font);
TMP_FontAsset font = damageNumber.GetFontMaterial();

//Set Scale:
damageNumber.SetScale(float scale);

//Prewarm Pooling (call this once):
damageNumber.PrewarmPool();

GUI Functions:
- You can either use the SpawnGUI(...) function or one of the following functions after the Spawn(...) function.
DamageNumber damageNumber = numberPrefab.Spawn(Vector3 position);

//Set Parent and Anchored Position relative to rectParent
damageNumber.SetAnchoredPosition(Transform rectParent, Vector2 anchoredPosition);

//Set Parent and Anchored Position relative to rectPosition
damageNumber.SetAnchoredPosition(Transform rectParent, Transform rectPosition, Vector2 anchoredPosition);

//Set Parent and Position to Mouse Position (canvasCamera as null if canvas is Screen Space - Overlay)
damageNumber.SetToMousePosition(RectTransform rectParent, Camera canvasCamera);
After spawning a popup, you can modify it in many ways.
To get started, reference the DamageNumber instance returned by the Spawn(...) function.

DamageNumber spawnedPopup = popupPrefab.Spawn(...);
Pretty much all the settings, you see in the inspector, can also be accessed through public variables.
Only change the variables of the spawned popup. The prefab should not be modified at runtime.


Changes to the text of the popup, will be updated 1 frame after it was spawned.
At a later point in time, you will need to update your changes manually, by calling the UpdateText() function.

Here is an example of a count down popup, by using a coroutine.
This coroutine can be started by using the StartCoroutine(CountDown()) function in any MonoBehaviour class.

public IEnumerator CountDown()
{
    //Spawn a new popup.
    DamageNumber spawnedPopup = popupPrefab.Spawn(transform.position);
    
    //Make the popup permanent, so we can fade it out manually.
    spawnedPopup.permanent = true;
    
    //Changes within the popup's first frame do not require the UpdateText() function.
    spawnedPopup.number = 3;
    spawnedPopup.numberSettings.bold = true;
    spawnedPopup.SetColor(Color.yellow);
    
    //Loop until the popup is zero.
    while (spawnedPopup.number > 0)
    {
        //Wait 1 second.
        yield return new WaitForSeconds(1);
        
        //Decrease number by 1.
        spawnedPopup.number--;
        
        //Lerp color towards red, as the number reaches 0.
        spawnedPopup.SetColor(Color.Lerp(Color.red, Color.yellow, spawnedPopup.number / 3f));
        
        //Update the text of the popup.
        spawnedPopup.UpdateText();
    }
    
    //Wait 1 second.
    yield return new WaitForSeconds(1);
    
    //Fade out the popup.
    spawnedPopup.FadeOut();
}


Most variable names usually match what you see in the inspector.
One exception are the feature toggle buttons. These are booleans and start with enable.

Below you will see a list of common variables to change the displayed text.

//These modify the displayed texts and number.
spawnedPopup.number = floatValue;
spawnedPopup.leftText = stringValue;
spawnedPopup.rightText = stringValue;
spawnedPopup.topText = stringValue;
spawnedPopup.bottomText = stringValue;

//These toggle the displayed features.
spawnedPopup.enableNumber = boolValue;
spawnedPopup.enableLeftText = boolValue;
spawnedPopup.enableRightText = boolValue;
spawnedPopup.enableTopText = boolValue;
spawnedPopup.enableBottomText = boolValue;

Besides variables, there are also various functions to modify your popups.

//Sets TextMeshPro's color.
spawnedPopup.SetColor(Color color);

//Sets TextMeshPro's color to a random color.
spawnedPopup.SetRandomColor(Color fromColor, Color toColor);
spawnedPopup.SetRandomColor(Gradient gradient);

//Enables and modifies TextMeshPro's vertex gradient.
spawnedPopup.SetGradientColor(Color topLeft, Color topRight, Color bottomLeft, Color bottomRight);
spawnedPopup.SetGradientColor(TMPro.VertexGradient vertexGradient);
//Changes TextMeshPro's font asset.
spawnedPopup.SetFontMaterial(TMPro.TMP_FontAsset font);

//Returns TextMeshPro's font asset.
TMPro.TMP_FontAsset font = spawnedPopup.GetFontMaterial();

//Returns an array of the popup's TextMeshPro components.
foreach (TMPro.TMP_Text tmp in spawnedPopup.GetTextMeshs())
{
    //Mesh popups return 1 component, but GUI popups return 2.
}
//Makes the popup follow a target and add its instance ID to the spam group.
//The ID prevents popups, of different targets, from interacting with each other.
spawnedPopup.SetFollowedTarget(Transform target);

//Sets the scale of the popup.
spawnedPopup.SetScale(float scale);

//Sets the position of the popup.
spawnedPopup.SetPosition(Vector3 position);
Hints:
Damage Numbers Pro works with Unity 2021.3 (or higher).
Only requires TextMeshPro which is installed by default anyways.

This asset should work out-of-the-box.
Contact me if you have any issues.
Some popups look rather white in the demo scene.
Those white popups are supposed to glow.
Look into the Glow Effect section (above) if you want glowing popups.


I have errors after installing the package.
Make sure you have TextMeshPro Version 2.1 (or higher) installed.


How do I modify this asset's code ?
You can duplicate and rename the existing DamageNumberMesh.cs or DamageNumberGUI.cs scripts.
Then you can edit your duplicate, you will have a couple of event functions to help you implement your custom features.
If you have a cool idea for, feel free to let me know.


My popups are shaking or jittering when following a gameobject.
First try setting the Update Delay in the Performance section to 0.
If you still see jittering set the Follow Speed to 1000 for an exact following.


I am getting warning messages in the demo.
This is because of an update to text mesh pro and you don't need to worry about it.
When you create your own damage numbers (see Create section), they won't log any warnings.


The namespace DamageNumbersPro could not be found.
This issue is often caused by Assembly Definition Reference assets.
If your script is located in a subfolder of an Assembly Definition Reference asset, you need to reference DamageNumbersPro in that asset.
Alternatively you could move your script to another folder, which is not affected by an Assembly Definition Reference.


If you were not able to solve your issues on your own, please contact me.
I am happy to help.
Glow Requirements:
- Bloom Post Processing
- HDR

Once you have Bloom and HDR you can create glowing popups.
The glow depends on your Color Intensity (tmp material) and Bloom Settings (post-processing).


Built-In Render Pipeline:
- Enable HDR in your graphics settings.
- Install Post Processing Stack v2 from the package manager.
- Add Bloom post-processing to your game.


Universal Render Pipeline:
- Enable HDR in your Universal Render Pipeline Asset.
- Use the volume component to add Bloom post-processing to your game.


HD Render Pipeline:
- Use the volume component to add Bloom post-processing to your game.
3D:
- If you want the popup to render through other objects, set the material's shader to "TextMeshPro/Distance Field Overlay".
- If you have issues with the shader, enable Main ➔ 3D Game ➔ Render Through Walls in the damage number's inspector instead.
- The Sorting Group component can be used to make certain popups render above others.


2D:
- Use the Sorting Group component to adjust the render order.


GUI:
- Render order depends on the rectParent of the damage number.
- Look into the GUI Functions listed under the Spawn section above.
Note:
In most cases performance impact will be unnoticeable.
If you are spawning something like 40 popups per second you will start to notice it though.
In that case there are several things you can do to improve it.


1. Enable Pooling
Under the performance tab of the damage number's inspector you can enable the pooling feature.
This will improve spawn performance by quite a bit.


2. Spam Control
Go to the spam control tab of the damage number's inspector.
You can either enable the Combination or the Destruction feature.
Both will massively improve performance by lowering the number of active popups.
They will also make popups more readable which is another plus.


3. Reduce Lifetime
Go to the main tab of the damage number's inspector.
You can reduce the Lifetime of the damage number here.
This will significantly improve performance.


4. Increase Update Delay
Go to the performance tab of the damage number's inspector.
You can find a setting called Update Delay which controls how many frames per second the popup is updated.
Increasing the delay or reducing the fps will boost performance.


5. Spawn Smarter
Some game's have dozens of enemies all taking damage at various locations in the scene.
Avoid spawning popups at far away and irrelevant locations, only spawn them if the camera is within rendering distance.
There are several ways to prioritize certain enemies over others and avoid unnecessary popups.


If you still have issues after looking into these, please contact me.
I am happy to help.
Damage Numbers Pro supports Game Creator 1 and Game Creator 2.
It also supports the Stats Module and even works with formulas.

Read below for a quick guide.


[Image]

1. Open the Game Creator.zip file included in the asset.
2. Open the Version 1 or 2 folder depending on your version of Game Creator.
3. Always extract the Basic.cs file but only extract the Stats.cs file if you use the stats module.

Note:
- Extract Version 1 into the Game Creator folder.
- Extract Version 2 into the Damage Numbers Pro folder.




Next follow the Create and Customize section under Tutorial.
Once you have your damage number prefab you are done, ignore the Spawn section.


[Image]

There are 2 custom instructions (or actions).
Read below to find out which one to use.

Important:
Drag your damage number prefab into the Prefab field.
Only dragging works for some reason.



Basic Popup:
- Spawns a number or text popup and offers several options.

Stats Popup: (in Game Creator 2)
- Does everything Basic Popup does.
- Contains the same settings that Change Attribute or Stat instructions have.
- Uses those settings to calculate the number of the popups.

Stats Popup: (in Game Creator 1)
- Does everything Basic Popup does.
- Searches for a Change Attribute or Stat action in the same collection (prefers neighbours).
- Automatically calculates the number based on the Change action.


Triggering this action should result in spawning a popup.
Unless you forgot to assign the prefab or the target's position is off camera.

If you can't figure this out on your own, please contact me.
I am happy to help.
Damage Numbers Pro supports Playmaker.
Read below for a quick guide.


[Image]

Open the Playmaker.zip file included in the asset and extract it.



Next follow the Create and Customize section under Tutorial.
Once you have your damage number prefab you are done, ignore the Spawn section.


[Image]

There are two custom actions you can choose from.
The Spawn Popup action should be easier to use.

Spawn Popup: Spawns a single popup whenever the state is entered.
Auto Spawn Popup: Spawns a popup whenever a specified variable changes.

In both cases you first need to drag your prefab into the prefab field.
Prefabs contain pretty much all the settings of your damage number.
You should have a prefab ready after following the Create and Customize section.


[Image]

Auto Spawn Popup

Changes to the checked variable will be detected.
Depending on the conditions a damage number will be spawned.

The state has to remain active to spawn new popups.
May need it's own separate PlayMakerFSM and a Get Fsm Float action.

Additionally you have the option to use the detected change as the number.
So you can automatically spawn numbers whenever an entity is damaged (or healed).


I think the rest will be pretty much self-explanatory.
Please let me know if you have any questions.


Click here to view the old documentation for version 3.