Hi
Never be taught about arrays in College so everything I know has been crafted together from what I’ve seen and heard. Done loads of googling and haven’t found anything useful of what I want to do.
Got a prefab and want to spawn it random locations. I’ve make a load of spawn points where I wouldn’t mind it spawning so I decided to put them in an array. I’ve seen a few ways to pick a random value from an array but won’t work with mine.
I have set the array up with find with tags so i just need it to randomly pick a transform from that array.
Can anyone help please.
public GameObject hazard;
public GameObject[] hazardSpawn;
public int hazardCount;
public int multiply = 2;
public float spawnWait;
public float startWait;
public float waveWait;
void Start ()
{
hazardSpawn = GameObject.FindGameObjectsWithTag ("HazardSpawn");
StartCoroutine (SpawnWaves ());
}
IEnumerator SpawnWaves ()
{
yield return new WaitForSeconds (startWait);
while (true)
{
for (int i = 0; i < hazardCount; i++)
{
Transform spawnPoint = hazardSpawn[Random.Range(0, hazardSpawn.Length)]; //this is what I tried
Quaternion spawnRotation = Quaternion.identity;
Instantiate (hazard, hazardSpawn, spawnRotation);
yield return new WaitForSeconds (spawnWait);
}
//hazardCount needs to be multiplied here (my little reminder)
yield return new WaitForSeconds (waveWait);
}
}
}