O'Reilly logo

Building an FPS Game with Unity by John P. Doran

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required