- Home /
Two InvokeRepeating separate functions turning to work a t the same time
Hi,
In my Update function I have two InvokeRepeating commands that are calling for separate function. I have set it so that the first one will start one second before the other and after that there should always be 2 seconds before repeating again. Everything works fine on a first shot but after this, they start working at the same time even I would kind of like them to "take turns". Any ideas?
And oh, couple lines of code say more than hundred words:
void Update () {
if(Input.GetKeyDown("s")){
if(shooting==false){
InvokeRepeating("ShootEmpty", 0, 2);
InvokeRepeating("Shoot", 1, 2);
shooting=true;
}
else if(shooting==true){
CancelInvoke("ShootEmpty");
CancelInvoke("Shoot");
shooting=false;
}
}
}
Your answer
Follow this Question
Related Questions
Invoking does not work, but why? 1 Answer
What is the difference between InvokeRepeating & Invoke and how can they be used? 1 Answer
how does invokerepeating work 2 Answers
Loop a function, once per second, X number of times 1 Answer
Coroutine in place of InvokeRepeating in need of start at time parameter 1 Answer