As the title suggests, I basically have two identical InvokeRepeating loops in my script, and one works as it should while the other doesn’t.
void Update () {
if (Input.GetKeyDown(KeyCode.Z) & (grass1 == false)) {
beginning = false;
grassone = true;
grasstwo = false;
grassthree = false;
grass1 = true;
grass2 = false;
grass3 = false;
InvokeRepeating("Grass1", 0, .25f);
}
if (Input.GetKeyDown(KeyCode.X) & (grass2 == false)) {
beginning = false;
grassone = false;
grasstwo = true;
grassthree = false;
grass1 = false;
grass2 = true;
grass3 = false;
InvokeRepeating("Grass2", 0, .25f);
}
if (Input.GetKeyDown(KeyCode.C) & (grass3 == false)) {
beginning = false;
grassone = false;
grasstwo = false;
grassthree = true;
grass1 = false;
grass2 = false;
grass3 = true;
InvokeRepeating("Grass3", 0, .25f);
}
if (grassone == true) {
CancelInvoke("Grass2");
CancelInvoke("Grass3");
}
if (grasstwo == true) {
CancelInvoke("Grass1");
CancelInvoke("Grass3");
}
if (grassthree == true) {
CancelInvoke("Grass1");
CancelInvoke("Grass2");
}
if (beginning == true) {
InvokeRepeating("Grass2", 0, .25f);
}
}
There’s my entire update function, I’m sure most of it is unnecessary but I didn’t want to leave anything important out. My issue is this part:
if (beginning == true) {
InvokeRepeating("Grass2", 0, .25f);
}
Instead of invoking the Grass2 function every .25 seconds like
if (Input.GetKeyDown(KeyCode.X) & (grass2 == false)) {
beginning = false;
grassone = false;
grasstwo = true;
grassthree = false;
grass1 = false;
grass2 = true;
grass3 = false;
InvokeRepeating("Grass2", 0, .25f);
}
does perfectly, it does it at a much, much faster rate. It is worth noting that I installed Unity and Visual Studios a week ago and am very new, so I’m probably missing something obvious. Any help would be appreciated, thanks!