Hey everyone,
I’m doing a couroutine for health regeneration and i start the couroutine in void Start() method but it just never starts. When i put it into void Awake() it does work.
So couroutines cannot be started from Start method?
Another question is why does visual studio sometimes put private in front of the update methods or start/awake methods?
This is my code:
void Start()
{
StartCoroutine(HealthRegeneration());
}IEnumerator HealthRegeneration()
{
while (true)
{
if (currentHealth < maxHealth.GetValue() && canRegenerate)
{
currentHealth += healthRegeneration.GetValue();
Debug.Log("Healed for " + healthRegeneration.GetValue());
yield return new WaitForSeconds(healthRegenerationTickRate.GetTickRate());
}
else
{
yield return new WaitForSeconds(healthRegenerationTickRate.GetTickRate());
}
}
}
This does not work.
But when i put the couroutine start into awake it works.
void Awake()
{
currentHealth = maxHealth.GetValue();
if (canRegenerate)
{
StartCoroutine(HealthRegeneration());
}
}