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.Spawn(Vector3.zero, Random.Range(1,100));

            //Set the rect parent and anchored position.
            damageNumber.SetAnchoredPosition(rectParent, new Vector2(0, 0));
        }
    }
}
[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:
//Basic:
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);
DamageNumber damageNumber = numberPrefab.Spawn(Vector3 position, float number, Color color);
DamageNumber damageNumber = numberPrefab.Spawn(Vector3 position, float number, Transform followedTransform, Color color);

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

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 have to call one of these 3 functions after spawning a GUI popup.
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);
Hints:
Damage Numbers Pro works with Unity 2020.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.


Upgrading from a version lower than 4.0
First you will need to delete your existing "Damage Numbers Pro" folder.
Then you can cleanly import the 4.0 version through the package manager.
You will also need to redo your prefabs and edit a little bit of your code to fix things.
The CreateNew(...) function has been renamed to Spawn(...).


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.