I’m having trouble with a damage over time script. using yield return new WaitForSeconds(1); either doesn’t wait for anything or causes the loop to only occur once.
If I put yield return new WaitForSeconds(1); inside the loop the loop will not repeat
If I put it after the loop doesn’t wait and finishes instantly.
I have tried changing the while loop to while(true) and adding an if statement in the loops to change the true variable to false but that didn’t work either.
any suggestions? i’m not getting any errors.
public IEnumerator ApplyDamageOverTime(float time, float damage)
{
float perSecond = damage / time;
float taken = 0;
Debug.Log("Running DoT script. Taking " + damage + " damage over " + time + " seconds." + " I will take " + perSecond + " per second");
while (taken < damage)
{
yield return new WaitForSeconds(1);
taken += perSecond;
Debug.Log("Ticking for " + perSecond + " damage. " + taken + " has now been taken");
}
}