Enemy AI Kit

Complete enemy AI pipeline: state machine, patrol, chase, health, and wave spawning with debug visualization.

6 scripts intermediate Starter kit Complete AI pipeline for enemies

The full files for this kit are not published yet, so there is no download. 4 of its 6 scripts are in the library and linked below. The preview shows how the main pieces fit.

What is inside

What it does

  • 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

Setup, in order

  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)

If something does not work

Enemies never notice the player
EnemyChaseAI looks for an object tagged Player. Tag your player, and put walls on a layer selected in Obstacle Layers so line of sight is blocked only by what should block it.
Patrolling enemies stop at the first waypoint
Assign at least two waypoints and pick a patrol mode (Loop, PingPong or Random). Waypoints must be reachable on the ground the enemy walks on.

Preview

An excerpt of the kit's main types, and the Inspector fields they expose.

InspectorExcerpt

Fields from the kit's preview excerpt; the full kit has more.

Detection Radius 10
Field Of View 120
Chase Speed 5
On Player Detected ()
List is Empty
On Attack Range ()
List is Empty
Waypoints Transform · Size 0
Patrol Mode None (PatrolMode)
Excerpt
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
}