how do i make a script that calculate how much damage did i loss

hey, i have a player with 100 health points. everytime i get hit by an enemy, i lose a random number between 5-20 hp. i have made a prefab with the 3d text, created a font and made an animation to the text so it will be above the head of the player and go up and disapear. the text in that prefab represent the number of health points that i have loss. like if i lost 10 hp (health points) than it will instantiate the prefab with the text "10" on it. the problem is, the hp i lose is random and i dont know how to make it work... thanks.

This is pretty simple.

Your HP is stored in a variable, right?

Just update what the 3D text says when you lose HP like this:

YourText.Text = hp;

If that doesn't work, you'll need someway to change your hp number value to a string. That really depends on which language you are using, I think.

EDIT

Since you clarified that this is displaying the damage done, try looking at it this way.

I am unsure how you are causing your HP to deplete. It could be that the enemy is directly depleting your HP. Or it could be that your player receives the value of damage done, and then depletes his own HP.

In either case...what you need to do is this:

YourText.Text = damageDone;

If for some reason you can't do that, then you can do this:

int temp = hpBeforeDamage;
/* Damage is dealt */
YourText.Text = hpBeforeDamage - currentHP;