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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.