Attack Delay

Hello guys,

I am making game but I just started and learning to make game.

Maybe I made the 5-10% of it.

I want to know if how to code an “Attack Delay”.

Did you get it?

I am planning to loop but I don`t know what to put.

I tried this:


time = 0;

while (time < 10) {
        if (time%2 == 0)
              attack;
        else
              rest;
}

but it is not working.

My game`s timer = 50.

If you know the game DOTA maybe you will get my point if the two creeps meet each other they will attack each other.

Thanks

int timer = 0;
int delay = 60; // how long you want it to be between each attack

private void update()
{
     timer--;
     if(timer<=0)
     {
          attack();
          timer = delay;
     }
} 

Thank you for the quick response.

How long is the delay in seconds?

if may game`s timer = 50.

Game timers are measured in ticks/updates.

Game usually has 60 updates/ticks per second.

So what we get is that 1 update/tick is 1 second / 60 = 0.016(7) seconds.

Thank you very much for the explanation.