Hi community! In my game, I am making a system to spawn random furniture at random spots in my home. To do this, I have several GameObject Arrays in my script, each array for 1 furniture. Then I have a Transform Array for spawnpoints. It chooses a random furniture gameobject from each array using Random.Range(0,furngroup1.length)
then chooses a random spawnpoint from the array using Random.Range(0,spawnpoints.length)
. After that I instantiate the chosen furniture at each chosen spawnpoint position. It all works well, except for 1 issue.
The exact code for choosing each spawnpoint is this:
sp1 = Random.Range(0,spawnpoints.length);
sp2 = Random.Range(0,spawnpoints.length);
sp3 = Random.Range(0,spawnpoints.length);
sp4 = Random.Range(0,spawnpoints.length);
sp5 = Random.Range(0,spawnpoints.length);
sp6 = Random.Range(0,spawnpoints.length);
But there is a chance that sp1 will be 7, but so will sp3, or sp2 and sp5, etc etc etc.
I made a workaround for it where it randomizes the numbers if sp1 == sp2, sp2 == sp3, etc and it works, however the numbers will change 3 or 4 times before finally being all different. Is there any way to generate the numbers without choosing one of the same value of another one?