I’m confused on this situation.
I have 8 objects that I want to randomly spawn at different locations to find and collect when my game starts.
I have 10 empty gameobjects as Spawn Points and I want the game to randomly choose 8 of those spawn points to place each of the 8 individual objects I have to collect. I tagged all of the 8 objects as “SpawnPoint”.
I am using this page link text as an example but I’m not sure what to really do… Any help would be extremely appreciated!
Just put them into an array or list if they aren’t already and do
spawnLocation = spawnPostions[Random.Range(0,9)]
You need to do the following:
Use FindGameObjectsWithTag to have all of your spwan points in a list of gameobject.
Make a loop that will run 8 times.
In the loop use
var r = Random.Range(0,7)
to get a random number between 0 and 7 (total of 8 possibilities).
Then get the position of the random chosen spwan point, something like:
var position = listofspwanpointas[r].transform.position;
Then just use Instantiate to spwan your objects.