x


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;
  }
 }
}
more ▼

asked Jul 17 '12 at 12:15 PM

Kitai gravatar image

Kitai
1 1

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x50

asked: Jul 17 '12 at 12:15 PM

Seen: 231 times

Last Updated: Jul 17 '12 at 12:24 PM