A
A
Artem Zuev2020-12-30 17:43:01
C++ / C#
Artem Zuev, 2020-12-30 17:43:01

How to restrict coroutine?

In my game, I use coroutine to spawn coins and medkits (health recovery) with this code:

IEnumerator Coin()
    {
        while (!Player.lose)
        {
                float newPos = a[new System.Random().Next(0, a.Length)];
                Instantiate(coin, new Vector2(-11f, newPos), Quaternion.identity);
                yield return new WaitForSeconds(time);
        }
    }

But with this code, the coin and first aid kit spawn immediately when the game starts. How can I fix this? How can I make coroutine start working a few seconds after the start of the game?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2020-12-30
@18382774

add to the beginning of WaitForSeconds?
Or not launch it right away.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question