Patrolling the area
Having different enemy groups on the map and hidden under the fog is already quite a challenge for the player. However, finding idle enemies while exploring the map is not very exciting. We can make it more fun and dynamic by adding patrol behavior to the enemies, so they are moving around between two points on the map.
Since we are using Unity’s NavMesh system, it is very simple to modify the existing Enemy
ComponentNavMesh
script and add the patrol behavior, so the enemy will be able to walk around the area, attack a unit when a collision is detected, and chase the unit if it tries to escape.
Open the existing script located at Scripts | Enemy | EnemyComponentNavMesh.cs
and add the following variables inside the class, before the declaration of the existing Start
method:
private int _currentPoint; private Vector3 _startPosition; private Vector3[] _points = new Vector3[2] { new Vector3(-10, 0, 0), new Vector3(10, 0, 0) };
The three...