<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: John Lawrie</title>
    <description>The latest articles on DEV Community by John Lawrie (@dalanchoo).</description>
    <link>https://dev.to/dalanchoo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4242408%2F376909c4-ecd5-4d4b-8637-c18662591980.jpg</url>
      <title>DEV Community: John Lawrie</title>
      <link>https://dev.to/dalanchoo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dalanchoo"/>
    <language>en</language>
    <item>
      <title>How to Build an Enemy Spawn Trigger in Unity (C#)</title>
      <dc:creator>John Lawrie</dc:creator>
      <pubDate>Fri, 13 Nov 2026 08:32:30 +0000</pubDate>
      <link>https://dev.to/dalanchoo/how-to-build-an-enemy-spawn-trigger-in-unity-c-5ec1</link>
      <guid>https://dev.to/dalanchoo/how-to-build-an-enemy-spawn-trigger-in-unity-c-5ec1</guid>
      <description>&lt;p&gt;This tutorial teaches you how to build a simple enemy spawning system in Unity. Enemies spawn when the player walks into a trigger. They spawn at spawn points you designate. The enemies disappear when the player touches them. The trigger keeps spawning enemies until it has spawned the total amount specified.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F46ve3m4s6w9vudxi1x5g.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F46ve3m4s6w9vudxi1x5g.gif" alt="What you will build in this tutorial" width="516" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Unity 6.6 (6000.6.8f1)&lt;/li&gt;
&lt;li&gt;Basic familiarity with the Unity Editor (Hierarchy, Inspector, and Project windows)&lt;/li&gt;
&lt;li&gt;The free &lt;strong&gt;First Person + Third Person | Character Controllers&lt;/strong&gt; package (also known as the Starter Assets) from Unity Technologies&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Set up the project
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a new project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Unity Hub, create a new project and choose the &lt;strong&gt;Universal 3D&lt;/strong&gt; template.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhhflzhim6l8xd1hbppc5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhhflzhim6l8xd1hbppc5.png" alt="Unity Hub New project screen with the Universal 3D template selected" width="800" height="443"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check the empty project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is what an empty project looks like.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpfmdmxgtpmu7idndez2o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpfmdmxgtpmu7idndez2o.png" alt="Empty Universal 3D project open in the Unity Editor" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Add a floor
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a plane&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go to &lt;strong&gt;GameObject &amp;gt; 3D Object &amp;gt; Plane&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuzf025hple5aqeirbk6h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuzf025hple5aqeirbk6h.png" alt="GameObject menu with 3D Object &gt; Plane selected" width="487" height="606"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reset the transform&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the Inspector, right-click the &lt;strong&gt;Transform&lt;/strong&gt; header and choose &lt;strong&gt;Reset&lt;/strong&gt;. This puts the floor at the origin.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmv8pn8a34t8k4x3fcwqx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmv8pn8a34t8k4x3fcwqx.png" alt="Transform context menu in the Inspector with Reset highlighted" width="799" height="493"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Enlarge the floor&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Set the Scale to &lt;strong&gt;(5, 1, 5)&lt;/strong&gt;. A Unity plane is 10 × 10 meters by default, so this gives you a 50 × 50 meter floor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvui0izbcatmj98qd26io.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvui0izbcatmj98qd26io.png" alt="Transform Scale set to 5, 1, 5" width="799" height="252"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Import the Starter Assets
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Open the Asset Store tab&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click the &lt;strong&gt;Asset Store&lt;/strong&gt; tab to activate it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F34cp55gqnspa3c1p2qs2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F34cp55gqnspa3c1p2qs2.png" alt="Asset Store tab in the Unity Editor" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Go to the Asset Store website&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Search online&lt;/strong&gt; to open the Asset Store.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fviaual4wsb0hasxweuq2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fviaual4wsb0hasxweuq2.png" alt="Search online button in the Asset Store tab" width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Search for the Starter Assets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Enter &lt;strong&gt;Starter Assets Third Person&lt;/strong&gt; in the search bar at the top, then click the magnifying glass icon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6n9igiuip6lvkldf5l44.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6n9igiuip6lvkldf5l44.png" alt="Asset Store search bar with Starter Assets Third Person entered" width="800" height="521"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Select the package&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;First Person + Third Person | Character Controllers&lt;/strong&gt; from &lt;strong&gt;Unity Technologies&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgb0t35ce8jp3dsllb7pa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgb0t35ce8jp3dsllb7pa.png" alt="Search results with First Person + Third Person | Character Controllers from Unity Technologies highlighted" width="800" height="698"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add it to your assets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Add to My Assets&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4u9fghraqgnjj5gjn82v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4u9fghraqgnjj5gjn82v.png" alt="Add to My Assets button on the First Person + Third Person | Character Controllers page" width="799" height="673"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Open the Package Manager&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Back in Unity, open the Package Manager with &lt;strong&gt;Window &amp;gt; Package Management &amp;gt; Package Manager&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhuoz5ruqronjsz6esjqw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhuoz5ruqronjsz6esjqw.png" alt="Window menu with Package Management &gt; Package Manager selected" width="800" height="647"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Download the package&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Under &lt;strong&gt;My Assets&lt;/strong&gt;, select &lt;strong&gt;First Person + Third Person | Character Controllers&lt;/strong&gt; and click &lt;strong&gt;Download&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe43ceaqnn7bjil50pwbi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe43ceaqnn7bjil50pwbi.png" alt="Package Manager showing First Person + Third Person | Character Controllers with the Download button" width="799" height="442"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Import the package&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the download finishes, click &lt;strong&gt;Import 2.0.2 to project&lt;/strong&gt;. Your version number may differ.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0tqenrhvb3iyd3mdicfn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0tqenrhvb3iyd3mdicfn.png" alt="Package Manager showing the Import 2.0.2 to project button" width="800" height="137"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Confirm the files&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Import Unity Package&lt;/strong&gt; window, leave everything checked and click &lt;strong&gt;Import&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs5a351gdjdrpwhdxi9yh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fs5a351gdjdrpwhdxi9yh.png" alt="Import Unity Package window listing the files in the Starter Assets folder" width="661" height="717"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Install the dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When asked to install or upgrade dependencies, click &lt;strong&gt;Install/Upgrade&lt;/strong&gt;. If Unity asks to restart the editor, click &lt;strong&gt;Yes&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnwvrx0gu7tj21qfp7tvo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnwvrx0gu7tj21qfp7tvo.png" alt="Dialog asking to install or upgrade the package dependencies" width="461" height="297"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Add the player
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Open the Prefabs folder&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the Project window, go to &lt;code&gt;Assets/Starter Assets/Runtime/ThirdPersonController/Prefabs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj8inyw2fix6l3h9pvb74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj8inyw2fix6l3h9pvb74.png" alt="Prefabs folder showing the six Starter Assets prefabs" width="800" height="314"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Drag the player into the scene&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Drag &lt;code&gt;NestedParentArmature_Unpack&lt;/code&gt; from the Project window into the Hierarchy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc5mvdxfkakvev9c5fy7q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc5mvdxfkakvev9c5fy7q.png" alt="Hierarchy with NestedParentArmature_Unpack added" width="493" height="275"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Delete the original Main Camera&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Select the &lt;strong&gt;Main Camera&lt;/strong&gt; that came with the template, the one at the top of the Hierarchy, and press &lt;strong&gt;Delete&lt;/strong&gt; or select &lt;strong&gt;Delete&lt;/strong&gt; from the right-click menu. The prefab brings its own camera, and two cameras would conflict.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fayl8zg4vt2l4x3lr1nse.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fayl8zg4vt2l4x3lr1nse.png" alt="Right-click menu on the original Main Camera with Delete selected" width="712" height="454"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Select the player&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the Hierarchy, click the arrow next to &lt;code&gt;NestedParentArmature_Unpack&lt;/code&gt; to expand it, then select &lt;code&gt;PlayerArmature&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4qhnz0m4p51ghczrmewt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4qhnz0m4p51ghczrmewt.png" alt="Expanded NestedParentArmature_Unpack with PlayerArmature selected" width="529" height="343"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Center the player&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the Inspector, set its &lt;strong&gt;Position&lt;/strong&gt; to &lt;strong&gt;(0, 0, 0)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2ie8xh7bctlt525sn9hj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2ie8xh7bctlt525sn9hj.png" alt="PlayerArmature Transform with Position set to 0, 0, 0" width="591" height="303"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The parent object is a container that groups the player and its cameras. The character itself is &lt;code&gt;PlayerArmature&lt;/code&gt;, so that’s the object to position.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Test the player&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click the &lt;strong&gt;Game&lt;/strong&gt; tab, then press &lt;strong&gt;Play&lt;/strong&gt;. Use &lt;strong&gt;WASD&lt;/strong&gt; to move, the &lt;strong&gt;mouse&lt;/strong&gt; to look around, &lt;strong&gt;Space&lt;/strong&gt; to jump, and &lt;strong&gt;Shift&lt;/strong&gt; to sprint.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhzrd7szk1kh2xqijmtrr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhzrd7szk1kh2xqijmtrr.png" alt="Play button in the Unity toolbar" width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you click inside the Game view, the mouse cursor is hidden and locked. Press &lt;strong&gt;Esc&lt;/strong&gt; to get it back.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7tn3iwge9n6rv3o4cfzp.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7tn3iwge9n6rv3o4cfzp.gif" alt="Third-person character walking, turning, and jumping on the floor" width="720" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the character falls through the floor, stop Play mode and set the &lt;strong&gt;Y&lt;/strong&gt; position of &lt;code&gt;PlayerArmature&lt;/code&gt; to &lt;strong&gt;0.1&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Save the scene&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While the game runs, the &lt;strong&gt;Play&lt;/strong&gt; button becomes a &lt;strong&gt;Stop&lt;/strong&gt; button. Click it to stop the game, then press &lt;strong&gt;Ctrl + S&lt;/strong&gt; to save the scene. Changes made during Play mode are lost when you stop, so make any adjustments after you exit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy4dhtcih223xzq92ghs0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy4dhtcih223xzq92ghs0.png" alt="Play button highlighted as Stop while the game is running" width="238" height="99"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Create the enemy
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Make folders for your files&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Make a &lt;code&gt;SpawnTutorial&lt;/code&gt; folder with &lt;code&gt;Materials&lt;/code&gt;, &lt;code&gt;Prefabs&lt;/code&gt;, and &lt;code&gt;Scripts&lt;/code&gt; inside to keep your work separate from the Starter Assets.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuqt1wg6bm2242my7jia6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuqt1wg6bm2242my7jia6.png" alt="SpawnTutorial folder containing Materials, Prefabs, and Scripts" width="598" height="222"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create the capsule&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First you create the enemy in the scene. Later, you turn it into a prefab.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;strong&gt;GameObject &amp;gt; 3D Object &amp;gt; Capsule&lt;/strong&gt; to create a capsule for the enemy. A white capsule appears in the Scene view and in the Hierarchy as &lt;code&gt;Capsule&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Rename it to &lt;code&gt;Enemy&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnenbkcs6iv78oh3zhw4u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnenbkcs6iv78oh3zhw4u.png" alt="Renamed the capsule to Enemy" width="799" height="529"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Make the enemy red&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Give the enemy a simple red material to mark it as hostile.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the Project window, open &lt;code&gt;SpawnTutorial/Materials&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Right-click in the empty area and choose &lt;strong&gt;Create &amp;gt; Material&lt;/strong&gt;. In some Unity 6 versions, it’s under &lt;strong&gt;Create &amp;gt; Rendering &amp;gt; Material&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Rename it &lt;code&gt;EnemyRed&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faq0chu2ilwipmveldmuv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faq0chu2ilwipmveldmuv.png" alt="Renamed the material to EnemyRed" width="799" height="465"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;With &lt;code&gt;EnemyRed&lt;/code&gt; selected, find &lt;strong&gt;Base Map&lt;/strong&gt; in the Inspector. It has a small color box on the right.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcuj5ig6336p6somzq09l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcuj5ig6336p6somzq09l.png" alt="Base Map property with its color box on the right" width="708" height="736"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click the color box and pick red. You can type &lt;code&gt;FF0000&lt;/code&gt; into the Hexadecimal field for pure red, or choose a slightly darker red like &lt;code&gt;CC0000&lt;/code&gt;, which looks less harsh under lighting.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqv4ia5pi5zadrj5mq9vw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqv4ia5pi5zadrj5mq9vw.png" alt="Color picker with red selected" width="349" height="1021"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Close the color picker.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Apply the material to the capsule.&lt;/p&gt;

&lt;p&gt;Drag &lt;code&gt;EnemyRed&lt;/code&gt; from the Project window onto the capsule, either in the Scene view or on &lt;code&gt;Enemy&lt;/code&gt; in the Hierarchy. The capsule turns red.&lt;/p&gt;

&lt;p&gt;The capsule may sit partly in the floor. That's fine, since spawned enemies get their position from spawn points.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F63mcsa0um0dr9n2aala9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F63mcsa0um0dr9n2aala9.png" alt="The enemy capsule after the material has been applied" width="799" height="496"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Make the collider a trigger&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A normal collider is solid, so the player would bump into the capsule. A trigger collider lets the player walk into it, and Unity sends an &lt;code&gt;OnTriggerEnter&lt;/code&gt; message that your script will use to remove the enemy.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select &lt;code&gt;Enemy&lt;/code&gt; in the Hierarchy.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the &lt;strong&gt;Capsule Collider&lt;/strong&gt; component, check &lt;strong&gt;Is Trigger&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft3p2b34oqyc8bw8967cw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft3p2b34oqyc8bw8967cw.png" alt="Capsule Collider with Is Trigger checked" width="705" height="556"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Turn it into a prefab&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A prefab is a reusable template saved in your project. You can create one by dragging a GameObject into the Project window. You will assign this prefab to the spawner so it knows what to create when the player touches the trigger. You no longer need the &lt;code&gt;Enemy&lt;/code&gt; in the Hierarchy window. It was just used to create the prefab, so you can delete it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Drag &lt;code&gt;Enemy&lt;/code&gt; from the Hierarchy into the &lt;code&gt;SpawnTutorial/Prefabs&lt;/code&gt; folder in the Project window.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F32kogbgr4n4lkrcy0gdv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F32kogbgr4n4lkrcy0gdv.png" alt="Enemy prefab in the SpawnTutorial/Prefabs folder" width="800" height="794"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;code&gt;Enemy&lt;/code&gt; in the Hierarchy and press &lt;strong&gt;Delete&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check the player's tag&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Enemy&lt;/code&gt; script identifies the player by its tag, so &lt;code&gt;PlayerArmature&lt;/code&gt; needs the &lt;strong&gt;Player&lt;/strong&gt; tag. The Starter Assets already set this tag, but it’s worth confirming.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select &lt;code&gt;PlayerArmature&lt;/code&gt; in the Hierarchy.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the Inspector, confirm &lt;strong&gt;Tag&lt;/strong&gt; is set to &lt;strong&gt;Player&lt;/strong&gt;. If it isn't, choose &lt;strong&gt;Player&lt;/strong&gt; from the drop-down.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxloer5eyr847d3nhyydg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxloer5eyr847d3nhyydg.png" alt="PlayerArmature Inspector with Tag set to Player" width="800" height="301"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create the Enemy script&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The enemy removes itself when the player touches it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In &lt;code&gt;SpawnTutorial/Scripts&lt;/code&gt;, right-click and choose &lt;strong&gt;Create &amp;gt; Scripting &amp;gt; MonoBehaviour Script&lt;/strong&gt;. Name it &lt;code&gt;Enemy&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Double-click &lt;code&gt;Enemy&lt;/code&gt; to open it in your code editor, and replace its contents with this code:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;UnityEngine&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Enemy&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;MonoBehaviour&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;OnTriggerEnter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collider&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CompareTag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Player"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Destroy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gameObject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Save the file and switch back to Unity. Unity recompiles the script automatically.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Select the &lt;code&gt;Enemy&lt;/code&gt; prefab in &lt;code&gt;SpawnTutorial/Prefabs&lt;/code&gt;. In the Inspector, click &lt;strong&gt;Add Component&lt;/strong&gt; and choose &lt;code&gt;Enemy&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5z0qb3vpse7fdj93wmfv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5z0qb3vpse7fdj93wmfv.png" alt="Enemy prefab Inspector with the Enemy script component added" width="418" height="555"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unity calls &lt;code&gt;OnTriggerEnter&lt;/code&gt; when another collider enters the enemy's trigger. The player's Character Controller counts as a collider, so no Rigidbody is needed.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CompareTag("Player")&lt;/code&gt; is a way to check whether the object is the player. It's faster than &lt;code&gt;other.tag == "Player"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Destroy(gameObject)&lt;/code&gt; deletes the enemy entirely. If you wrote &lt;code&gt;Destroy(this)&lt;/code&gt; instead, you would only remove the script, and the capsule would be left in the scene.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  8. Test the enemy
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Drag the &lt;code&gt;Enemy&lt;/code&gt; prefab into the Scene view a few meters in front of the player. Unity places it on the floor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Press &lt;strong&gt;Play&lt;/strong&gt; and walk into the capsule. It disappears.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Stop Play mode and delete the test enemy from the scene.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fofy8k5qoir5z8x9mz3yq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fofy8k5qoir5z8x9mz3yq.gif" alt="Player walking into the red capsule, which disappears" width="759" height="468"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Create the spawn trigger
&lt;/h2&gt;

&lt;p&gt;The spawn trigger is a box that starts spawning enemies when the player touches it. It's transparent orange until the player activates it, at which point it disappears. Enemies spawn at spawn points that are assigned to the trigger. The trigger spawns a tunable number of enemies, ensuring only a set number are alive at once.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create the SpawnGroupTrigger script&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In &lt;code&gt;SpawnTutorial/Scripts&lt;/code&gt;, create a new &lt;strong&gt;MonoBehaviour Script&lt;/strong&gt; named &lt;code&gt;SpawnGroupTrigger&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Double-click it to open it in your code editor, and replace its contents with this code:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Collections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Generic&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;UnityEngine&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;UnityEngine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Events&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;RequireComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BoxCollider&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SpawnGroupTrigger&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;MonoBehaviour&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;SerializeField&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;GameObject&lt;/span&gt; &lt;span class="n"&gt;enemyPrefab&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;SerializeField&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Transform&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;spawnPoints&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;SerializeField&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;totalToSpawn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;SerializeField&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;maxAlive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;SerializeField&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;minDistanceFromPlayer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3f&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;SerializeField&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;disableAfterUse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;SerializeField&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;UnityEvent&lt;/span&gt; &lt;span class="n"&gt;onTriggered&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;GameObject&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;aliveEnemies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;GameObject&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Transform&lt;/span&gt; &lt;span class="n"&gt;player&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;spawnedCount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;isSpawning&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;hasTriggered&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Called when the component is first added. Makes the box a trigger automatically.&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;Reset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;GetComponent&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BoxCollider&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isTrigger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;OnTriggerEnter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collider&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CompareTag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Player"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isSpawning&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;disableAfterUse&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;hasTriggered&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;enemyPrefab&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;spawnPoints&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;spawnPoints&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Debug&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LogWarning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"{name}: assign an enemy prefab and at least one spawn point."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;player&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;other&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;hasTriggered&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;isSpawning&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;spawnedCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;onTriggered&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;Update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;isSpawning&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Destroyed objects compare equal to null in Unity, so this drops enemies the player removed.&lt;/span&gt;
        &lt;span class="n"&gt;aliveEnemies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RemoveAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;enemy&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;enemy&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;aliveEnemies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Count&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;maxAlive&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;spawnedCount&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;totalToSpawn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Transform&lt;/span&gt; &lt;span class="n"&gt;point&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FindFreeSpawnPoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;point&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// No usable point right now. Try again next frame.&lt;/span&gt;
            &lt;span class="nc"&gt;SpawnEnemy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;spawnedCount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;totalToSpawn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;isSpawning&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Returns a spawn point that has no enemy on it and isn't too close to the player.&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Transform&lt;/span&gt; &lt;span class="nc"&gt;FindFreeSpawnPoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;spawnPoints&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Start at a different point each time so enemies spread out.&lt;/span&gt;
            &lt;span class="nc"&gt;Transform&lt;/span&gt; &lt;span class="n"&gt;point&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;spawnPoints&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;spawnedCount&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;spawnPoints&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;point&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;player&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nc"&gt;Vector3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Distance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;player&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;minDistanceFromPlayer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IsOccupied&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;IsOccupied&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Transform&lt;/span&gt; &lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;GameObject&lt;/span&gt; &lt;span class="n"&gt;enemy&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;aliveEnemies&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;enemy&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nc"&gt;Vector3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Distance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mf"&gt;0.5f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;SpawnEnemy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Transform&lt;/span&gt; &lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;GameObject&lt;/span&gt; &lt;span class="n"&gt;enemy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Instantiate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;enemyPrefab&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rotation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;aliveEnemies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;enemy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;spawnedCount&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Draws the trigger box and spawn points in the Scene view so you can see them while editing.&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;OnDrawGizmos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;BoxCollider&lt;/span&gt; &lt;span class="n"&gt;box&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;GetComponent&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BoxCollider&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;box&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Gizmos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Color&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.6f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nc"&gt;Gizmos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;matrix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;localToWorldMatrix&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nc"&gt;Gizmos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DrawWireCube&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;center&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nc"&gt;Gizmos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;matrix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Matrix4x4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;identity&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;spawnPoints&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nc"&gt;Gizmos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Color&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Transform&lt;/span&gt; &lt;span class="n"&gt;point&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;spawnPoints&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;point&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nc"&gt;Gizmos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DrawSphere&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.3f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nc"&gt;Gizmos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DrawLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;point&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Save the file and switch back to Unity.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Settings:&lt;/strong&gt; &lt;code&gt;[SerializeField]&lt;/code&gt; makes a private field editable in the Inspector. &lt;code&gt;[Min(1)]&lt;/code&gt; prevents the Inspector from accepting zero or negative counts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Reset&lt;/code&gt;:&lt;/strong&gt; is called when you add the component in the editor. It enables &lt;strong&gt;Is Trigger&lt;/strong&gt; on the Box Collider, and &lt;code&gt;[RequireComponent]&lt;/code&gt; ensures the Box Collider exists.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;OnTriggerEnter&lt;/code&gt;:&lt;/strong&gt; is called when something enters and, if conditions are met, starts spawning enemies. It ignores everything not tagged &lt;strong&gt;Player&lt;/strong&gt; and ignores the player when a wave is already spawning. It fires only once if &lt;strong&gt;Disable After Use&lt;/strong&gt; is checked. It also invokes &lt;code&gt;onTriggered&lt;/code&gt;, so you can add actions in the Inspector without writing code. You’ll use it to turn off the trigger’s visual.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Update&lt;/code&gt;:&lt;/strong&gt; is called every frame. It removes enemies the player has destroyed from its list of alive enemies. In Unity, a destroyed object equals &lt;code&gt;null&lt;/code&gt;. Then it spawns new enemies until either &lt;strong&gt;Max Alive&lt;/strong&gt; enemies are alive or &lt;strong&gt;Total To Spawn&lt;/strong&gt; have been spawned.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;FindFreeSpawnPoint&lt;/code&gt;:&lt;/strong&gt; picks a spawn point without an enemy on it that is at least &lt;strong&gt;Min Distance From Player&lt;/strong&gt; away from the player. Without this check, an enemy could spawn on top of another enemy or inside the player, where it would be touched and removed instantly. If no point qualifies, spawning waits until one frees up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;SpawnEnemy&lt;/code&gt;:&lt;/strong&gt; spawns an enemy at the chosen point and adds it to the list.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;OnDrawGizmos&lt;/code&gt;:&lt;/strong&gt; draws the trigger as an orange wireframe box and the spawn points as red spheres. Gizmos only appear in the Scene view. The &lt;code&gt;TriggerVisual&lt;/code&gt; cube you add next shows the trigger in the game.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because the spawner keeps track of its own enemies, the &lt;code&gt;Enemy&lt;/code&gt; script doesn't need to know the spawner exists.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Create the trigger in the scene
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;strong&gt;GameObject &amp;gt; Create Empty&lt;/strong&gt; and rename it &lt;code&gt;SpawnTrigger1&lt;/code&gt;. The number makes it easy to add more triggers later, like &lt;code&gt;SpawnTrigger2&lt;/code&gt; further along the path.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add Component&lt;/strong&gt; and choose &lt;code&gt;SpawnGroupTrigger&lt;/code&gt;. Unity adds a &lt;strong&gt;Box Collider&lt;/strong&gt; with &lt;strong&gt;Is Trigger&lt;/strong&gt; already checked.&lt;/li&gt;
&lt;li&gt;Set the Box Collider's &lt;strong&gt;Center&lt;/strong&gt; to &lt;strong&gt;(0, 1, 0)&lt;/strong&gt; and its &lt;strong&gt;Size&lt;/strong&gt; to &lt;strong&gt;(6, 2, 1)&lt;/strong&gt;. This makes a box 6 meters wide and 2 meters tall that sits on the floor.&lt;/li&gt;
&lt;li&gt;Set its &lt;strong&gt;Position&lt;/strong&gt; to &lt;strong&gt;(0, 0, 5)&lt;/strong&gt;, 5 meters in front of the player.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3tggu2v0ibkblpmkb1el.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3tggu2v0ibkblpmkb1el.png" alt="Box Collider and Spawn Group Trigger added to SpawnTrigger1" width="441" height="659"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Make the trigger visible&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The trigger is invisible in the game, so add a see-through box that shows where it is.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In &lt;code&gt;SpawnTutorial/Materials&lt;/code&gt;, create a material named &lt;code&gt;TriggerZone&lt;/code&gt;. In the Inspector, set &lt;strong&gt;Surface Type&lt;/strong&gt; to &lt;strong&gt;Transparent&lt;/strong&gt;, then set the &lt;strong&gt;Base Map&lt;/strong&gt; color to orange using the hex value &lt;code&gt;FF8C00&lt;/code&gt;, and set its &lt;strong&gt;A&lt;/strong&gt; (alpha) value to &lt;strong&gt;80&lt;/strong&gt; so the box is see-through.&lt;/li&gt;
&lt;li&gt;Right-click &lt;code&gt;SpawnTrigger1&lt;/code&gt; in the Hierarchy and choose &lt;strong&gt;3D Object &amp;gt; Cube&lt;/strong&gt;. This creates a new cube as a child of &lt;code&gt;SpawnTrigger1&lt;/code&gt;. Rename the cube &lt;code&gt;TriggerVisual&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Set its &lt;strong&gt;Position&lt;/strong&gt; to &lt;strong&gt;(0, 1, 0)&lt;/strong&gt; and its &lt;strong&gt;Scale&lt;/strong&gt; to &lt;strong&gt;(6, 2, 1)&lt;/strong&gt; to match the Box Collider.&lt;/li&gt;
&lt;li&gt;Remove the cube's &lt;strong&gt;Box Collider&lt;/strong&gt; component: click the &lt;strong&gt;⋮&lt;/strong&gt; menu on the component and choose &lt;strong&gt;Remove Component&lt;/strong&gt;. Otherwise, the cube is solid, and the player bumps into it.&lt;/li&gt;
&lt;li&gt;Drag the &lt;code&gt;TriggerZone&lt;/code&gt; material onto &lt;code&gt;TriggerVisual&lt;/code&gt;, either in the Scene view or in the Hierarchy.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvds7ccg3w7odm81b7ed6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvds7ccg3w7odm81b7ed6.png" alt="See-through orange box marking the spawn trigger" width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Add spawn points
&lt;/h3&gt;

&lt;p&gt;Spawn points are empty GameObjects that mark where enemies appear.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create three empty GameObjects named &lt;code&gt;SpawnPoint1&lt;/code&gt;, &lt;code&gt;SpawnPoint2&lt;/code&gt;, and &lt;code&gt;SpawnPoint3&lt;/code&gt;, and drag them onto &lt;code&gt;SpawnTrigger1&lt;/code&gt; in the Hierarchy to make them its children. This keeps the Hierarchy tidy.&lt;/li&gt;
&lt;li&gt;Set their positions to &lt;strong&gt;(-2, 1, 4)&lt;/strong&gt;, &lt;strong&gt;(0, 1, 4)&lt;/strong&gt;, and &lt;strong&gt;(2, 1, 4)&lt;/strong&gt;. Because they're children of the trigger, these positions are relative to it, so this puts them in a row 4 meters past the trigger.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;strong&gt;Y&lt;/strong&gt; position of each is &lt;strong&gt;1&lt;/strong&gt; because the capsule is 2 meters tall and spawns centered on the point, so a height of 1 puts it on the floor.&lt;/p&gt;

&lt;p&gt;This tutorial uses three spawn points because &lt;strong&gt;Max Alive&lt;/strong&gt; is set to 3 in the next step. Each point holds one enemy at a time, so you need at least as many spawn points as &lt;strong&gt;Max Alive&lt;/strong&gt;. With fewer points, fewer enemies can be alive at once.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Connect the settings
&lt;/h3&gt;

&lt;p&gt;Select &lt;code&gt;SpawnTrigger1&lt;/code&gt; and fill in the &lt;code&gt;SpawnGroupTrigger&lt;/code&gt; fields in the Inspector:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Enemy Prefab:&lt;/strong&gt; drag in the &lt;code&gt;Enemy&lt;/code&gt; prefab from &lt;code&gt;SpawnTutorial/Prefabs&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spawn Points:&lt;/strong&gt; click the arrow next to &lt;strong&gt;Spawn Points&lt;/strong&gt; to expand it, set the size to &lt;strong&gt;3&lt;/strong&gt;, and drag &lt;code&gt;SpawnPoint1&lt;/code&gt;, &lt;code&gt;SpawnPoint2&lt;/code&gt;, and &lt;code&gt;SpawnPoint3&lt;/code&gt; into &lt;strong&gt;Element 0&lt;/strong&gt;, &lt;strong&gt;Element 1&lt;/strong&gt;, and &lt;strong&gt;Element 2&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Total To Spawn:&lt;/strong&gt; 6&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Max Alive:&lt;/strong&gt; 3&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Min Distance From Player:&lt;/strong&gt; 3&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Disable After Use:&lt;/strong&gt; checked&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On Triggered:&lt;/strong&gt; click &lt;strong&gt;+&lt;/strong&gt;, drag &lt;code&gt;TriggerVisual&lt;/code&gt; into the object field, and choose &lt;strong&gt;GameObject &amp;gt; SetActive (bool)&lt;/strong&gt;. Leave the checkbox unchecked. This hides the box once the trigger fires.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fld2nloikdgndretr78f5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fld2nloikdgndretr78f5.png" alt="SpawnGroupTrigger component with the Enemy prefab and three spawn points assigned" width="459" height="785"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Scene view, you now see the orange trigger box, with lines to the three red spawn points.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqmwzxefop1q5ia0ez3rc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqmwzxefop1q5ia0ez3rc.png" alt="Scene view showing the trigger box and spawn point gizmos" width="493" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Test it
&lt;/h3&gt;

&lt;p&gt;Press &lt;strong&gt;Play&lt;/strong&gt; and walk through the orange box. The box disappears, and up to three enemies appear. Touch an enemy to remove it. Another enemy spawns when a free spawn point is at least 3 meters away from you. This continues until six enemies have spawned in total. If spawning pauses, move away from the spawn points.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ff07ovfenfs8tbpjquu8y.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ff07ovfenfs8tbpjquu8y.gif" alt="Player walking through trigger, enemies spawning, and being replaced as the player touches them" width="516" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If nothing spawns, check the &lt;strong&gt;Console&lt;/strong&gt; for a warning about a missing prefab or spawn points.&lt;/p&gt;

&lt;h2&gt;
  
  
  Save and troubleshoot
&lt;/h2&gt;

&lt;p&gt;When you finish testing, stop Play mode and press &lt;strong&gt;Ctrl + S&lt;/strong&gt; to save the scene.&lt;/p&gt;

&lt;p&gt;If the trigger or enemies don't behave as expected, check the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Check the Console.&lt;/strong&gt; Resolve any script errors. A warning appears if the enemy prefab is missing or the spawn-point list is empty.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the player tag.&lt;/strong&gt; Select &lt;code&gt;PlayerArmature&lt;/code&gt; and confirm its &lt;strong&gt;Tag&lt;/strong&gt; is set to &lt;strong&gt;Player&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the colliders.&lt;/strong&gt; Confirm that &lt;strong&gt;Is Trigger&lt;/strong&gt; is checked on the &lt;code&gt;Enemy&lt;/code&gt; prefab's Capsule Collider and on &lt;code&gt;SpawnTrigger1&lt;/code&gt;'s Box Collider.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the spawn points.&lt;/strong&gt; On &lt;code&gt;SpawnTrigger1&lt;/code&gt;, expand &lt;strong&gt;Spawn Points&lt;/strong&gt; and confirm that all three entries have a spawn point assigned.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Move away from the spawn points.&lt;/strong&gt; An enemy won't spawn at a point that is occupied or too close to the player. Spawning resumes when a suitable point becomes available.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check the trigger visual.&lt;/strong&gt; If the orange box doesn't disappear, confirm that &lt;strong&gt;On Triggered&lt;/strong&gt; targets &lt;code&gt;TriggerVisual&lt;/code&gt;, calls &lt;strong&gt;GameObject &amp;gt; SetActive (bool)&lt;/strong&gt;, and has the checkbox unchecked.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Next steps
&lt;/h2&gt;

&lt;p&gt;You now have a very basic trigger that spawns enemies. You control where they appear, how many appear at once, and how many appear in total. If you want to expand upon this example, here are some ideas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have the enemies chase the player. You can bake a NavMesh for the floor and add a NavMesh Agent to the &lt;code&gt;Enemy&lt;/code&gt; prefab. Set the enemy's destination to the player's position each frame.&lt;/li&gt;
&lt;li&gt;Have multiple &lt;code&gt;SpawnGroupTrigger&lt;/code&gt; objects in the level. Later ones can become active only when the player kills all enemies from earlier ones.&lt;/li&gt;
&lt;li&gt;Have the enemies shoot simple projectiles at the player.&lt;/li&gt;
&lt;li&gt;Give the enemies bodies like the player’s instead of simple capsules.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I built and tested this project and took the screenshots myself. I used AI as an editor to help shape and polish the writing.&lt;/p&gt;

&lt;p&gt;You can download the &lt;a href="https://github.com/dalanchoo/spawntriggertutorial" rel="noopener noreferrer"&gt;complete project on GitHub&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>unity3d</category>
      <category>csharp</category>
      <category>gamedev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
