Question by
syw-gaming · Oct 25, 2016 at 02:15 PM ·
positionrandomgenerationblocks
Random.Range not repeat same position
var dupeobject : GameObject;
function Start(){
yield WaitForSeconds(0);
var position : Vector3 = Vector3(Random.Range(-50,10),Random.Range(-10,5),Random.Range(-100,20));
Instantiate(dupeobject,position,Quaternion.identity);
yield WaitForSeconds(0);
//Destroy(gameObject);
}
I have this code that generates blocks in random position and it works but some times it generates blocks at the same position ,how can I fix it?
Comment
If you want to avoid duplicate positions you could fill a List with all the positions already used up and check with each new random if it already exists before adding. Or you create a list with a for loop so it's predefined positions already and remove each position you chose.
Your answer
Follow this Question
Related Questions
Clear path from A to B 4 Answers
How to generate a random 2d world for a 2d endless runner 0 Answers
Easy chunk prefab creation 0 Answers
Check if a random position is inside a collider (Vector 2D) 0 Answers