So I’m using Invoke to call a couple of functions every second. This is the code:
void healthRegen()
{
playersTemp.isExposed = false;
if(healthScript.curHealth < 100.0f)
{
increaseHealth();
//Debug.Log (playersTemp.exposedTimer);
}
}
void tempRegen()
{
if(playersTemp.currBodyTemp < 37.0f && healthScript.curHealth == 100.0f)
{
increaseTemp();
}
}
void increaseTemp()
{
playersTemp.currBodyTemp += 0.5f;
if(playersTemp.currBodyTemp == 37.0f)
{
CancelInvoke("tempRegen");
playersTemp.exposedTimer = 0.0f;
}
}
void increaseHealth()
{
healthScript.curHealth += 0.5f;
if(healthScript.curHealth == healthScript.maxHealth)
{
CancelInvoke("healthRegen");
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.E))
{
InvokeRepeating("healthRegen", 0.0f, 1.0f);
InvokeRepeating("tempRegen", 0.0f, 1.0f);
}
}
Now for some reason the healthRegen() function is cancelling invoking upon reaching the players possible maximum health. Now the tempRegen() is quite similar it increases the players currBodyTemp when this reaches the maximum value of 37 it should cancel invoking. But for some reason it doesn’t? The numbers bounce back between 36.5 to 37 and I can’t seem to figure out why. Any suggestions?
Edit: Added missing code.