🧠 What Happens In-Game? (Function Overview)
🎯 Player Detection
The spawner detects the player when they are within the defined activationRange.

👀 Field of View Check
The spawner checks if the player is within its field of view — meaning the player must be generally in front of it (based on dot product comparison).

🚀 Object Spawning
If both conditions are met (distance and field of view), the spawner creates a new object (e.g., projectile or missile):

Either directly towards the player

Or along the spawner's Z-axis (based on the useFixedZDirection setting)

🔫 Firing Rate
The spawner only fires if enough time has passed, based on the fireRate value (e.g., 2 = 2 shots per second).

💥 Ammo Handling
If isAmmoUnlimited is disabled, the spawner consumes ammo with each shot. Once ammo reaches 0, it stops firing.

🧠 Manual Reload
You can manually reload ammo during runtime by calling the method:

csharp
Kopieren
Bearbeiten
ReloadAmmo();
🧰 How to Use the Script in Unity
1. Prepare the Prefab
Create an object (e.g., a sphere, rocket, or particle system).

Drag it into the Project window to create a Prefab.

Make sure the prefab is active and not empty.

2. Create an Empty GameObject
Right-click in the Hierarchy → Create Empty

Rename it, e.g., EnemySpawner

Attach the Spawner script to this GameObject.

3. Adjust Values in the Inspector
Setting	Description
Object To Spawn	The prefab that should be spawned
Activation Range	How close the player must be to activate the spawner
Fire Rate	How fast it fires (e.g., 2 = two shots per second)
Use Fixed Z Direction	If true, the spawner fires straight along its Z-axis
Max Ammo	Max ammo (if unlimited ammo is disabled)
Gizmo Color	The color of the range circle in the Scene view
Show Range Gizmo	Toggle visibility of the activation range circle in the editor
Show Direction Gizmo	Toggle visibility of the spawner’s forward direction line in the editor
Gizmo Direction Length	Length of the forward-facing line in the Scene view

4. Set Main Camera as Player Target
Make sure your main camera has the tag MainCamera (default in Unity).

The spawner uses Camera.main to find the player.

5. Test the Spawner
Press Play

Move the camera (player) close to the spawner

You should see:

Console logs: “Spawner activated”, “Ammo left: X”, etc.

Objects being spawned and moving

👁️‍🗨️ What the Gizmos Show in the Scene View
These are editor-only visuals to help you place and configure the spawner:

Gizmo	Meaning
🔴 Circle	A wire sphere showing the activationRange
🔵 Line	A forward-facing line showing the direction the spawner fires
🎨 Color	The wire sphere’s color can be set in the Inspector

