itIt would be simpler to create to use events and fibers
usingUsing a fiber means you can yieldyield and sayreturn how many frames to wait until calling it should be called it again.
thenThen with a priority queue you can iterate over all events scheduled for the current frame.
IEnumerator<int> ai_script()
yield return 60;
while(true)
{
shootAtPlayer();
yield return 30;
}
}
and then in the gameloop
while(running){
frame++;
updateFysics();
IEnumerator<int> ie;
while((ie = delayQueue.Pop(frame))!=null){
if(ie.MoveNext()){//move next then does the call true means there is another wait, false means the task is done
delayQueue.add(ie,ie.Current+frame);//Current holds the delay requested
}
}
}
thisThis solution is heavy misuse of C# syntax, but you can use explicit Fibers instead.