InvokeRepeating for healthregen

Updated on November 13, 2018 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on November 9, 2018

Is there a way to update the invokerepeating?

what i mean with this is the following:

 

InvokeRepeating(“RegenHealth”, 1f / stats.healthRegenRate, 1f / stats.healthRegenRate);
}

void RegenHealth() {

if (gameMaster.pause == false) {
stats.curHealth += 1;
statusIndicator.SetHealth(stats.curHealth, stats.maxHealth);
Debug.Log(“Regen Invoke = ” + stats.healthRegenRate);
}

else {
stats.curHealth += 0;
}
}

//End of script

 

the stats.healthRegenRate is getting incremented outside of this script properly as seen in Debug.Log(“Regen Invoke = ” + stats.healthRegenRate)

however inside the InvokeRepeating it doesn’t seem to update the function, what can i do to solve this?

Thank you

  • Liked by
Reply
0 on November 13, 2018

Instead of InvokeRepeating you can also use a coroutine.

void Start()
{
StartCoroutine(RegenHealth());
}
private IEnumerator RegenHealth()
{
while(true)
{
//your stuff
yield return new waitForSeconds(1f / stats.healthRegenRate);
}
}

 

  • Liked by
Reply
Cancel