Random.Range always returns same value

I'm trying to make a small simulation of traveling salesman in Unity C# and I can't get through this, my code looks right but start and nxtCity vectors always result in the same position, I really can't understand why, could any of you help?

cities is the number of total cities

positions is the array of cities taken from cities generator these two values are right in unity editor

Here the code:

void Start()
        positions = cam.GetComponent<citiesGene>().positions;
        cities = cam.GetComponent<citiesGene>().cities;
        start = positions[Random.Range(0, cities)];
        transform.position = start;

    IEnumerator ChooseCity()
        while (true)
            nxtCity = positions[Random.Range(0, cities)];
            arrive = false;
            while (arrive == false)
                yield return new WaitForFixedUpdate();

Read more here: https://stackoverflow.com/questions/67929836/random-range-always-returns-same-value

Content Attribution

This content was originally published by XEDGit at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: