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 AIAll 5 ai & pathfinding scripts
- Enemy Chase AI Enemy AI that detects the player within radius, chases with line-of-sight, and returns to patrol when player escapes.
- Waypoint Patrol AI Enemy patrol between waypoints with configurable speed, wait times, and patrol patterns (loop, ping-pong, random).
- NavMesh Click-to-Move Click-to-move character controller using NavMeshAgent. Click anywhere to navigate, with destination marker and path line.
- A* Grid Pathfinding Grid-based A* pathfinding without NavMesh. Supports diagonal movement, weighted nodes, and debug visualization.
- Waypoint Patrol AI ProPro Advanced patrol AI with NavMesh pathfinding, player detection with awareness meter, alert states, group coordination, and patrol schedules.
What these scripts need
Read from each script's source, so this list stays in step with the code.
Requires NavMeshAgent on the same GameObject.
Uses the NavMesh API (UnityEngine.AI): bake a NavMesh with the AI Navigation package first.
Reads the legacy Input Manager (UnityEngine.Input). If Project Settings > Player > Active Input Handling is set to Input System Package only, Unity throws an InvalidOperationException; set it to Both.
Applies to: NavMesh Click-to-Move
Kits that build on them
Guides that use them
- Free Unity C# Scripts and Game Systems: 55 Copy-Paste Tools for Indie Games A catalog of 55 free Unity C# scripts and 13 game systems: movement, camera, health, save/load, UI, AI, mobile controls, inventory and dialogue.
- Building Enemy AI in Unity: From Patrol to Boss Fights Build enemy AI in Unity from simple patrol to advanced boss fights. Covers waypoint systems, chase behavior, A* pathfinding, wave spawning, and state machine-driven bosses.
- Procedural Generation in Unity: Dungeons, Day/Night and World Building Master procedural generation in Unity: random dungeon layouts, day/night cycles, timed events, and wave-based enemy spawning.