I have a loop function which is supposed to make a poison effect to the player, I feed it a value, it starts depleting 1 health per second the health based on the value, it works perfectly with one-digit numbers, but for some reason, if the value is double digits it depletes 2 health per second instead of one. Does anyone know why?
public int karmaValue;
public int karmaNo;
private HealthScript healthScript;
KRBar kRBar;
private void Start()
{
healthScript = GameObject.Find("Player Soul").GetComponent<HealthScript>();
kRBar = GetComponent<KRBar>();
}
private void Update()
{
KarmaDamage();
}
void KarmaDamage()
{
for (int i = 0; i < karmaValue; karmaNo--)
{
healthScript.karmaHealth -= 1; //Deplete Health
kRBar.SetKRHealth(healthScript.karmaHealth); //Visualize
KarmaNo(); //Make the next value equal to the original value
karmaValue = 0; //Make value 0 so it doesn't do the loop more than once
Invoke("NewKarma", 1); //Make new value 1 less the new value after 1 second
}
}
void KarmaNo()
{
karmaNo = karmaValue;
}
void NewKarma()
{
karmaValue = karmaNo;
}