I am currently creating a game where the player is on a square platform and I want the enemies to spawn randomly from the four edges of the platform. So far I am able to make my enemies spawn randomly from one edge, but don't know how to make them spawn from all four. I imagine it would work with a Vector3 array? But I am struggling to get this right. Please help!
My spawn code so far:
void SpawnRandomEnemy()
{
if(!playerControllerScript.gameOver && !playerControllerScript.hasFreezePowerup)
{
int enemyIndex = Random.Range(0, enemyPrefabs.Length);
Vector3 spawnPos = new Vector3(Random.Range(-spawnRange, spawnRange), 0, spawnPosZ);
Instantiate(enemyPrefabs[enemyIndex], spawnPos, enemyPrefabs[enemyIndex].transform.rotation);
}
}