Choosing a random location out of a list for an object to spawn at.

I’ve got a basic spawning script for enemies but I’m trying to make it so the enemies will spawn at a randomly chosen location out of a set that I input.

    public GameObject[] spawnObject;
	public GameObject[] spawnPosition;
	
	public float radius = 1.0f;
	public float minSpawnTime = 1.0f;
	public float maxSpawnTime = 10.0f;
	public bool constantSpawn = false;
	//public Transform spawnPosition;
	//Vector3 randomLocation;
	public float SpawnCount = 0f;
	public float LookAtDistance = 10.0f;
	public float Distance;
	public Transform Target;
	public float Damping = 5.0f;
	private Quaternion rotation;
	public bool deathspawn = true;
	
	void Start()
	{
		Target = GameObject.FindGameObjectWithTag ("Player").transform;

	
		

	}
	
	void Update(){
	
		Distance = Vector3.Distance (Target.position + Target.transform.forward, transform.position);
		
		if (Distance < LookAtDistance)
		{
			LookAt();
		}
		
	}
	
	void OnTriggerEnter(Collider Player)
	{
	
			Invoke("SpawnEnemy", Random.Range(minSpawnTime,maxSpawnTime));
		
		
		
	}
	
	void OnTriggerExit(Collider Player)
	{
	
		CancelInvoke ("SpawnEnemy");
		deathspawn = false;
		
	}
	

	void SpawnEnemy () 
	{
		
		//randomLocation = Random.insideUnitSphere * radius;
		
		
		//float spawnRadius = radius;
		int spawnObjectIndex = Random.Range(0,spawnObject.Length);
		int spawnPositionIndex = Random.Range (0, spawnPosition);
			
		//transform.position = Random.insideUnitSphere * spawnRadius;
			
		Instantiate(spawnObject[spawnObjectIndex],spawnPosition[spawnPositionIndex].position + randomLocation,spawnObject[spawnObjectIndex].transform.rotation);
		
		SpawnCount += 1f;
		
		if (constantSpawn == true && SpawnCount <= 5)
		{
			Invoke ("SpawnEnemy", Random.Range (minSpawnTime,maxSpawnTime));
			
			
		}

		
	}
	
	void LookAt(){

	rotation = Quaternion.LookRotation (Target.localPosition - transform.position);
	transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
		
	}
	
	public void SpawnDown (float reduction){
		
				SpawnCount -= reduction;

				if (deathspawn == true) {

					Invoke ("SpawnEnemy", Random.Range (minSpawnTime, maxSpawnTime));
				}
		}
	
}

I used a random selection for the enemies themselves but to be completely honest I got that section of the code from a tutorial and I am not really sure how everything is implemented into the code. The spawnObject allows me to assign multiple objects to be spawned and I’m asssuming the spawnObjectIndex is what chooses from a random object in that list so I copies that over for the spawnPosition but I’m not sure how to put it into the instantiate function. What I’ve got now leads to 5 errors. I’m assuming I did something wrong with the spawnPositionIndex () bit and I know I messed up the Instantiate.

Any assistance would be appreciated and if this is unclear please let me know and I’ll try to explain it better, it’s difficult to describe problems concerning stuff you don’t get very well

It’s a bit chaotic what you did there. So if you don’t mind I wont’ go trough your script but tell the basic idea how to do it. So you have the random locations in the spawnPosition array, so what you need to do is, just give that to the instantiate function, like this:

int spawnPositionIndex = Random.Range (0, spawnPosition.Length); // or Count can't remember right, anyway the length of the array list
 Instantiate(spawnObject[spawnObjectIndex],spawnPosition[spawnPositionIndex].transform.position,spawnPosition[spawnPositionIndex].transform.rotation);

edited it so others could have the good code too.