So I have this little tidbit of code:
[Server]
IEnumerator Regeneration()
{
while (!isDead)
{
yield return new WaitForSeconds(1f);
Debug.Log("Regeneration is running.");
float regenhealth;
float regenStam;
float regenMana;
if (currentHealth < maxHealth)
{
regenhealth = healthRegenerationRate;
//Debug.Log("Player should regenerate health.");
}
else
regenhealth = 0f;
if (currentStamina < maxStamina)
{
regenStam = staminaRegenerationRate;
Debug.Log("Player should regenerate stamina.");
}
else
regenStam = 0f;
if (currentMana < maxMana)
{
regenMana = manaRegenerationRate;
Debug.Log("Player should regenerate mana.");
}
else regenMana = 0f;
if (regenhealth > 0f || regenStam > 0f || regenMana > 0f)
{
Regenerate(regenhealth, regenStam, regenMana);
}
}
}
When my player dies, isDead is set to true and the coroutine stops - as intended. My question is, is that coroutine completely stopped or do I need to kill it manually?
I’m afraid that I’m actually starting multiple coroutines all in memory with new memory allocated for each one, which will eventually kill the game.