Random Object Spawn on Unique Locations.

Hello, I did some research for spawning random objects but they didn’t seem not I wanted. For an example, I have a terrain and there is a specific locations that I want an object to spawn there.

Here is what I should do:

1.) There is more than 5 spawn locations and 1 or more objects that I want to randomly instantiate in this locations.
2.) Instantiated Random Objects should not have to spawn again in the same location point.

How do I achieve this? I really appreciate any help. Thanks.

  1. Assuming these objects are saved in your Assets, make a list of objects:
    List object;

  2. Add all your objects to that list
    List.Add(Resources.Load(“RandomObjectName” as GameObject));

  3. Make a function that includes steps 4-6.

  4. Make a copy of that list and have a random number generator pick ‘n’ number of objects to spawn at that location

  5. Make a while loop that iterates ‘n’ times and contains: a random number generator that selects from 0 to the size of the copy of the list, and Instantiates that random number index, then removes that index from the list and repeats this until the while loop is over, move each object to right, left, or above the position when spawned for repeats

  6. Call this for each location

using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class SpawnObjects : MonoBehaviour {
//specify all gameobjects to spawn in editor
public GameObject SpawnableObjects;

         //private non editable in editor
         private Dictionary<Vector3, GameObject> _spawnedObjects = new Dictionary<Vector3, GameObject>();
         private System.Random Rand = new System.Random();
 
         //specify the spawn borders in editor
         public Vector3 MinSpawnRange;
         public Vector3 MaxSpawnRange;
 
         void Start()
         {
             for(int i=0; i < SpawnableObjects.Length; i++)
             {
                 Vector3 randPos = new Vector3(Rand.Next((int)MinSpawnRange.x, (int)MaxSpawnRange.x), Rand.Next((int)MinSpawnRange.y, (int)MaxSpawnRange.y), Rand.Next((int)MinSpawnRange.z, (int)MaxSpawnRange.z));
 
                 while (_spawnedObjects.Keys.Any(f => f.x == randPos.x && f.y == randPos.y && f.z == randPos.z))
                 {
                     randPos = new Vector3(Rand.Next((int)MinSpawnRange.x, (int)MaxSpawnRange.x), Rand.Next((int)MinSpawnRange.y, (int)MaxSpawnRange.y), Rand.Next((int)MinSpawnRange.z, (int)MaxSpawnRange.z));
                 }
 
                 Instantiate(SpawnableObjects*, randPos, Quaternion.identity);*

spawnedObjects.Add(randPos, SpawnableObjects*);
_
}*

}
}