X
X
XDecent2020-07-05 13:21:54
C++ / C#
XDecent, 2020-07-05 13:21:54

Why doesn't the method work correctly?

void Start()
    {
        InvokeRepeating("Spawn", Random.Range(1f,2f), Random.Range(1f,3f));
    }
    void Spawn()
    {
        Instantiate(target);
    }

I need the objects to spawn differently each time (with a different margin). But they spawn the same way.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zZaKko, 2020-07-05
@zZaKko

When you have registered a random time, it works once and does not randomize further.
That is, at the start, for example, it issued such randoms: then they remain forever until the coroutine is turned off. You can write a small timer in Update() and call the method you need through the usual Invoke(). If you can't, I can help. InvokeRepeating("Spawn", 1.5f, 2.5f);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question