- Home /
removing an int from a Random.Range
hey, sorry about the stupid title, couldn't really think of what to call this... heres the code:
var count : float = 0; var random : int = Random.Range(1,5); var planePrefab : Transform;
function Update() { count++; if(count >= 1000) { count = 0; CreatePlane(); random = Random.Range(1,5); } } function CreatePlane() { switch(random) { case 5: Instantiate( planePrefab, GameObject.Find("Spawner5").transform.position, Quaternion.identity); break; case 4: Instantiate( planePrefab, GameObject.Find("Spawner4").transform.position, Quaternion.identity); break; case 3: Instantiate( planePrefab, GameObject.Find("Spawner3").transform.position, Quaternion.identity); break; case 2: Instantiate( planePrefab, GameObject.Find("Spawner2").transform.position, Quaternion.identity); break; case 1: Instantiate( planePrefab, GameObject.Find("Spawner1").transform.position, Quaternion.identity); break; } }
what I want is to remove an option from the switch list, then, when all are gone, start again in a random order.
Answer by Extrakun · Jun 22, 2010 at 08:45 AM
Create an array holding the numbers 1 to 5, shuffle the array and read the numbers off. When you have read the 5th number, shuffle the array again.
Your answer
Follow this Question
Related Questions
Random Drops 2 Answers
For Loop isn't working properly! 1 Answer
Switching weapons/tools using a GameObject array 2 Answers
Room generator spawn 1 unique room 1 Answer
Random placement objects. 0 Answers