How to show the change in slider value

I have a boss in my game with a slider as a health bar, and I what I want to have happen is when the player hits the boss, it shows the amount of damage (how much the slider value decreased) that has been done. For example, if the boss is at 45% health and the player hits him and does 15% damage, I want to show that value next to the boss health bar.

You can create 2 health slider images (one over another)…when the boss gets hit, immediately set the image on top (which is visible at all times)…to the new health value, but use a coroutine to wait for some time (maybe 1 second) before you lerp the second image to the real health value, this will create a really nice effect, but make sure to set it up so that if the boss is hurt again, both the top image, and the hidden damage indicator, are first immediately set to the current (before damage) value of health…and then the top layer is set immediately to the new damage value to create a convincing effect…if you need any clarification or help, tell me…hope this atleast points you in the right direction

You can create 2 health slider images (one over another)…when the boss gets hit, immediately set the image on top (which is visible at all times)…to the new health value, but use a coroutine to wait for some time (maybe 1 second) before you lerp the second image to the real health value, this will create a really nice effect, but make sure to set it up so that if the boss is hurt again, both the top image, and the hidden damage indicator, are first immediately set to the current (before damage) value of health…and then the top layer is set immediately to the new damage value to create a convincing effect…if you need any clarification or help, tell me…hope this atleast points you in the right direction

Well in that case it is really easy…First you need to create a text gameobject and place it close to the healthbar, (where you want to display the damage) make sure it’s scaled properly to allow for multiple digits (you can customise it for color or anything, or even use Textmeshpro which is a free unity asset to create more customisable text)…these steps are very subjective and you will have to setup this yourself…

after that add this directive at the top of your script…

//if you are using the built in text, which i suppose you already have since you are using sliders with images
using UnityEngine.UI;

//if you are using TextMeshPro
using TMPro;

then create a reference to your text or textmeshpro in the script

//default
public Text deltaDamage;

//TextMeshPro
public TextMeshPro deltaDamage;

after that you can simply do this…

if(other.collider.tag == "Sword" )
     {
         if (PlayerAnimator.GetCurrentAnimatorStateInfo(0).IsName("hit"))
         {
             hit += 1;
             float damage = 7f;
             swordImpact.Play();
             anim.SetBool("damage", true);
             slider.value -= damage;
             deltaDamage.text = damage.ToString();
             ParticleSystem.Emit(100);
        } 
    }

make sure to set the text to nothing in the start method…

void Start()
{
  deltaDamage.text = "";
}

and it’s that simple…
hope this helps