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!