Unity AI & Pathfinding Scripts

5 free C# scripts 2 beginner2 intermediate1 advanced Unity 2022.3+ MIT licensed

Enemy behaviour in most games is a patrol, a chase, and a way to find a path between them. Waypoint Patrol AI walks a route with wait times, Enemy Chase AI detects the player, follows them while it has line of sight and gives up when it loses them, and the Pro patrol script combines both with an awareness meter.

For getting around, NavMesh Click-to-Move drives a NavMeshAgent from mouse clicks, and A* Grid Pathfinding finds paths on a grid with no NavMesh at all, which suits tile-based and 2D games. The NavMesh scripts need a baked NavMesh from the AI Navigation package.

Start with Enemy Chase AI

Enemy AI that detects the player within radius, chases with line-of-sight, and returns to patrol when player escapes.

EnemyChaseAI.cs · 12 Inspector fields · beginner

Open Enemy Chase AI
EnemyChaseAI.cs
Script EnemyChaseAI
Detection
Detection Radius 10
Field Of View 120
Require Line Of Sight
Obstacle Layers Nothing
Chase
Chase Speed 5
Rotation Speed 8
Give Up Distance 15
Attack Range 1.5
Target
Player Tag Player
Events
On Player Detected ()
List is Empty
On Player Lost ()
List is Empty
On Attack Range ()
List is Empty

All 5 ai & pathfinding scripts

What these scripts need

Read from each script's source, so this list stays in step with the code.

Kits that build on them

Guides that use them