Game Development Reference
In-Depth Information
Then, create your manager script in the normal way. For example, the following script
simply spawns the configurable enemy objects from a collection according to a simple re-
peating interval:
public class EnemySpawnManager : MonoBehaviour
{
public float spawnTime = 5f;
//The amount of time between each spawn.
public float spawnDelay = 3f;
//The amount of time before spawning starts.
public GameObject[] enemies;
//Array of enemy prefabs.
void Start ()
{
//Start calling the Spawn function repeatedly after a
delay.
InvokeRepeating("Spawn", spawnDelay, spawnTime);
}
void Spawn ()
{
//Instantiate a random enemy.
int enemyIndex = Random.Range(0, enemies.Length);
Instantiate(enemies[enemyIndex],
transform.position, transform.rotation);
}
}
Then, simply attach your script to the new empty game object. For it to function, you will
need to assign the prefabs of the types of enemies you want to appear in the scene by at-
taching them to the Enemies property, as shown in the following screenshot:
Search WWH ::




Custom Search