- Home /
Repeating the loop
Hi, for some reason the variable "town level" is only being randomized once, it should be getting randomized during each iteration of the loop but I might have forgetten about something. Help is much appreciated
for (int i = 0; i < numberOfIslands; i++) { x = Random.Range(200, 1000); y = Random.Range(100, 1000); z = Random.Range(-700, 700); offset = new Vector3(x, y, z); GameObject clone = Instantiate(platforms[Random.Range(0, platforms.Count)], transform.position + offset, Quaternion.Euler(-90, 0, 0)) as GameObject; clone.transform.parent = gameObject.transform; Townlevel = Random.Range(0, 20); if (Townlevel > 10) { levelOfTown = 1; } if (Townlevel < 10) { levelOfTown = 0; } }
The platforms connected to other prefab generation stuff so the town level is to essentially select what "list" goes into the generator (they all work as I've tested them). I can't understand what is happening to the town level value if it's only being generated once.
Thank you
Code looks okay. If you add a debug, check your console to see if it's actually doing anything:
Debug.Log ("Before random Townlevel="+Townlevel);
Townlevel = Random.Range(0, 20);
Debug.Log ("After random Townlevel="+Townlevel);
You should see a pair of debugs for each iteration of the loop.
Where are you actually using the Townlevel or levelOfTown variables to do something? I don't see them being used inside the loop. If you're using them outside the loop then the value is going to be deter$$anonymous$$ed by the last iteration of the loop.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Making a bubble level (not a game but work tool) 1 Answer
Unity 3.5 C# Problem 1 Answer
An OS design issue: File types associated with their appropriate programs 1 Answer