How to arrange gameobjects in random order?

I have 3 prefabs, and 3 slots that they can go into. I want the 3 objects to be arranged in a random order on those 3 slots, but no repeating objects. Here’s what I got so far:

    public Transform player;
    //the slots, i have 3 of them
    public Vector2[] newPositions;
    //the gameobjects, also 3 of them
    public GameObject[] circlePrefabs;

    private void Start()
    {
        SpawnCircles();
    }

    public void SpawnCircles()
    {
        //setting the position of those slots
        newPositions[0] = new Vector2(-1.5f, player.position.y + 10f);
        newPositions[1] = new Vector2(0f, player.position.y + 10f);
        newPositions[2] = new Vector2(1.5f, player.position.y + 10f);

        for (int i = 0; i < newPositions.Length; i++)
        {
            //this chooses a random object, and assigns it to the current slot in the loop
            int randomIndex = Random.Range(0, newPositions.Length);
            //instantiates
            Instantiate(circlePrefabs[randomIndex], newPositions*, Quaternion.identity);*

}
}
Here’s the catch: A random object is selected, so they sometimes repeat. I would like for all 3 to be added in, and am struggling with this. Thanks in advance!

Something like this should work. I didn’t test it so you might need to tweak it a little.

public class RandomSpawn : MonoBehaviour
{
    public List<Vector2> positions;
    public GameObject[] prefabs;
    
    private void AssignPositions()
    {
        for (int i = prefabs.Length - 1; i >= 0; i--)
        {
            int index = Random.Range(0, positions.Count);
            prefabs*.transform.position = positions[index];*

positions.RemoveAt(index);
}
}
}
This iterates through the list of positions and using a list instead of an array you can dynamically update the max range of the random.range.
Hope it helps! :slight_smile: