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? Code (CSharp): 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 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?
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.