I want to make 6 spawn points all that spawn a different character and i want the script to single out one of them at random so I can make him a target. Here’s what i got so far
using UnityEngine;
using System.Collections;
public class spawner : MonoBehaviour {
public GameObject[] characters;
public float spawnTime = 1f; // How long between each spawn.
public Vector3[] spawnPoints; // An array of the spawn points this enemy can spawn from.
public Transform trans;
public int randomIndex;
GameObject randomCharacter;
void Start () {
// Call the Spawn function after a delay of the spawnTime and then continue to call after the same amount of time.
InvokeRepeating ("Spawn", spawnTime, spawnTime);
trans = GetComponent <Transform> ();
randomIndex = Random.Range (0, 14);
randomCharacter = characters [randomIndex];
}
void Update (){
}
void Spawn ()
{
int spawnPointIndex = Random.Range (0, spawnPoints.Length);
Instantiate (randomCharacter, spawnPoints[spawnPointIndex], trans.rotation);
}
}