Resolved : Random.Range returns significantly high values

Hello,
I’m so new to unity, so please understand if my codes has low readability.
Following code prints -2, -16, 16, 2 only and NO OTHER VALUES.
I’m spending more than 6 hours until now, but I couldn’t find any solutions.

// sorry about strange Indexing...
int randomNumberGernerated = Random.Range(1, 50);
int newLoc = 0;
        if (randomNumberGernerated <= 6)
        {
            newLoc = - 1;
        }
        else if (randomNumberGernerated <= 12)
        {
            newLoc = - 8;
        }
        else if (randomNumberGernerated <= 18)
        {
            newLoc = + 1;
        }
        else if (randomNumberGernerated <= 24)
        {
            newLoc = + 8;
        }
        if (randomNumberGernerated <= 30)
        {
            newLoc = - 2;
        }
        else if (randomNumberGernerated <= 36)
        {
            newLoc = - 16;
        }
        else if (randomNumberGernerated <= 42)
        {
            newLoc = + 2;
        }
        else if (randomNumberGernerated <= 48)
        {
            newLoc = + 16;
        }
        else
        {
        }
        Debug.Log(newLoc);

Why is this print specific values only?
TMI : My Game including this code came up with so annoying infinite loop…

1 Like

line 20: else if

1 Like

Oh, it was my mistake…
Thanks a lot!

1 Like