I’ve three spots in a row at the top of the screen (represented by the ‘slideSpots’ array.) My goal is to press play and then have three objects (astronaut, rocket, satellite) from a list (represented by the ‘objects’ array) instantiate in each of those three spots. So, I want an astronaut in one of the spots. I want a rocket in another one of the spots, and I want the satellite in the last available spot. What’s happening currently when I press play is that three objects instantiate, but often I get repeats (two astronauts for example) and I’ve more than one object instantiated on one spot (overlap.)
Here’s my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RandomItems : MonoBehaviour {
public GameObject[] slideSpots;
public GameObject[] objects;
public GameObject theSpot;
public void Start()
{
SpawnSlideSpots();
SpawnSlideSpots();
SpawnSlideSpots();
}
void SpawnSlideSpots()
{
int spawn = Random.Range(0, slideSpots.Length);
int stuff = Random.Range(0, objects.Length);
theSpot = GameObject.Instantiate(objects[stuff], slideSpots[spawn].transform.position, Quaternion.identity);
}
}