- Home /
Unity|C#| Card Game: How to draw a card for each 0.5 secs?
The title explains everything.
The code doing so is this one:
for (int i = 0; i < 5; i++)
{
enemy.Push (cardDeckEnemy.Pop ());
}
What should be changed to do so?
With this, I mean, what code is required to pop a card each 0.5 secs, like, a time stop thing, to avoid from drawing all of them at the speed of the processor
Answer by IvovdMarel · Jul 17, 2016 at 10:55 PM
I recommend not using a for-loop, but instead use InvokeRepeating.
Example:
int nCardsToPush = 5;
void Start () {
InvokeRepeating("PopCard", 0, 0.5f);
}
void PopCard () {
if (nCardsToPush > 0) {
enemy.Push (cardDeckEnemy.Pop ());
nCardsToPush--;
} else {
CancelInvoke();
}
}
Answer by Padalino · Jul 18, 2016 at 12:10 PM
Have you tried the InvokeRepeating function? Then, you can Invoke a funcion, with a delay, and a cadence: InvokeRepeating("FunctionName", delay, cadence);
Hope this solved your question.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
C# | How to delay a method with parameters 2 Answers
My script only partially works 2 Answers
Out of memory during play 0 Answers
How do I get enemies to only chase me in certain areas 0 Answers