InvokeRepeating Not Funtioning

Hello everybody. I wrote this script which is supposed to make healthScript.SlimeDamage(); run every so often but it only executes once . What did I do wrong?

    void attackTimer(){
        slimeBasicAttack = true;   
    }

    void Update () {
        InvokeRepeating ("attackTimer", 100, 1000f);

        GameObject health = GameObject.Find ("Hero");
        //"Hero" can be replaced by name of GameObject that the the Health script is on
        Health healthScript = (Health)health.GetComponent (typeof(Health));
       
       
        if (slimeBasicAttack == true && dodge == false) {
            healthScript.SlimeDamage ();
            slimeBasicAttack = false;
        }
    }
}

You’re calling InvokeRepeating every frame in Update. It should be called only once.

–Eric

It still doesnt work :confused:

Did you try putting it in the “Start” function Blar321?

You are calling it after 100seconds and then you are asking it to repeat after a thousand seconds. Are you sure you are waiting long enough to see if it’s repeating?

+//

Yes… Still nothing :confused:

Yeah… I changed it to 10 and 100 and still nothing

I`m guessing either you still never waited 100 seconds to see the repeat, or the code broke in healthScript.SlimeDamage () method. Its bad code though really. You should cache the health and healthscript in the start function. You could even move the healthScript.SlimeDamage () call directly into the attackTimer method.

  1. change it to 5 and 5 just to make sure its running.
  2. put a Debug.Log into attackTimer