intermediate
Enemy AI Kit
Complete enemy AI pipeline: state machine, patrol, chase, health, and wave spawning with debug visualization.
Features
Finite state machine with clean enter/execute/exit lifecycle
Waypoint patrol with loop, ping-pong, and random patterns
Player detection with radius, FOV, and line-of-sight checks
Chase behavior with give-up distance and return-to-origin
Enemy health with damage, death events, and invincibility
Wave-based spawning with configurable waves and spawn points
Included Scripts
/enemy-ai-kit/
StateMachine.cs
State.cs
Setup Guide
1
Import all scripts into your project
2
Create enemy prefab with WaypointPatrol or EnemyChaseAI
3
Place waypoint Transform objects in the scene for patrol routes
4
Tag your player as 'Player' for detection to work
5
Add HealthSystem to enemies for health tracking
6
Set up WaveSpawner with spawn points and wave definitions
7
For advanced AI, use StateMachine with custom State classes
8
Select enemies in Scene to see debug gizmos (detection, patrol, FOV)
Code Preview
C#
// EnemyChaseAI.cs - Detection and chase
public class EnemyChaseAI : MonoBehaviour
{
[SerializeField] private float detectionRadius = 10f;
[SerializeField] private float fieldOfView = 120f;
[SerializeField] private float chaseSpeed = 5f;
public UnityEvent OnPlayerDetected;
public UnityEvent OnAttackRange;
// FOV + line-of-sight detection, chase, return to origin
}
// WaypointPatrol.cs - Patrol between points
public class WaypointPatrol : MonoBehaviour
{
[SerializeField] private Transform[] waypoints;
[SerializeField] private PatrolMode patrolMode;
// Loop, PingPong, Random patrol patterns
}Available Individually
These scripts are also available as standalone downloads: