Creating a Wave Health bar

Hey I’m Adri.
I’m creating a tower defense and I created a health bar that cover all the enemies health, but iI got a problem with that. If you click like 3-4 times for second, It goes well, but if you click 6-7 times for second It starts to go up and down.
Thats my code for updating the bar and the text:

HealthBarFillAmount -= PlayerPrefs.GetFloat("DamageDone");
        if (HealthBarFillAmount <= 0)
        {
            HealthBarFillAmount = 0;
        }
        waveHealthBar.fillAmount = HealthBarFillAmount / NextWaveHealth + 0.0f;
        PlayerPrefs.SetFloat("DamageDone", 0);
        EnemyHealthNow.text = HealthBarFillAmount.ToString("F2");

that’s the code that detects the damage done:

    public void EnemyHit()
    {
        EnemyBase EnemyScript = enemyToShoot.GetComponent<EnemyBase>();
        float EnemyHealth = EnemyScript.Health;
        float HealthEnemyTotal = EnemyHealth + PlayerPrefs.GetFloat("MainDamage");
        float DamageDone = HealthEnemyTotal - PlayerPrefs.GetFloat("MainDamage");
        float DamageDoneIfItsUnderZero;
        if (DamageDone >= 0)
        {
            PlayerPrefs.SetFloat("DamageDone", PlayerPrefs.GetFloat("MainDamage"));
        }else
        if (DamageDone < 0)
        {
            DamageDone *= -1;
            DamageDoneIfItsUnderZero = PlayerPrefs.GetFloat("MainDamage") - DamageDone;
            PlayerPrefs.SetFloat("DamageDone", DamageDoneIfItsUnderZero);
        }
       
    }

I call that void every time I click the screen.
I’m not good programming, I know, I just started on that because I’m studying 3D art and Design.
Sorry for my bad English.
Thanks.

This approach seems pretty weird to me. PlayerPrefs tends to be used for saving data, to persist it from one game to the next. You seem to be setting it with every hit, maybe as a poor man’s approach to sharing data between multiple components in your game? What’s the reasoning for setting a PlayerPrefs value every time you hit something?

Anyway, in general you should either add breakpoints and debug the code, or add some Debug.Log statements to understand what the values are at different times. Maybe you’ve got some other code modifying the values that you’ve forgotten about. (Maybe you have some code running somewhere to regenerate enemy health, for example.)