mardi 28 juillet 2020

How can I use the Random.Range's answer to set as the max value into the same Random.Range until it reaches 1

I want to create a script that generates a random number (between 1(min) and 9999(max)) and then I want the random number to become the new max for the same exact script.

Is there a way to create an equation or some sort of way to do this infinitely (until 1).

The only solution I have come up with is this:

private IEnumerator MyCoroutine()
{
    var a  = Random.Range(1, 9999 + 1);
    largeText.text = a.ToString();
    yield return new WaitForSeconds(2);
    if (a > 1)
    {
        var b  = Random.Range(1, a + 1);
        largeText.text = b.ToString();
        yield return new WaitForSeconds(2);
        if (b > 1)
        {
            //Then continues 'infinitely'
        }
    }
}

This is a solution, but I eventually run into the problem of having an extremely unwanted script.

Ofcourse I have the rest that I need with this script, and it does work, however I would like to know if there is an easier work around that doesn't involve me writing 1m lines of code.

Thank you!




Aucun commentaire:

Enregistrer un commentaire