Spawning multiple enemies at once

Taking this a little further, we can create another script that can be used to spawn multiple enemies at once.

  1. Go to the MyGame/Scripts folder, navigate to Create | New C# Script, and call it SpawnEnemiesOnTrigger. Once you've finished, double-click on the created file to open MonoDevelop.
  2. Once the file is opened, put in the following code if you're using RAIN:
    using UnityEngine; using System.Collections; using System.Collections.Generic; // List public class SpawnEnemiesOnTrigger : MonoBehaviour { // Enemy to spawn public GameObject enemy; // Where to be spawned at public List<Transform> spawnPoints; // Has this happened already? private bool hasTriggered = false; void OnTriggerEnter(Collider other) { //If the player ...

Get Building an FPS Game with Unity now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.