In 4 simple steps, create a modular waypoint system in Unity

Samarth Dhroov
3 min readOct 17, 2021

--

The exercise here demonstrates a simple way to implement waypoint system in Unity.

This solution requires navmeshagent to be in place. If needed, please check out the article here.

Create a C# script and attach it to the object that has shall move.

Unity
  • The waypoints in Unity are game objects with only a transform component. To store them in an efficient structure, List seems an ideal choice.
C#

As soon as the script is loaded, the script component on the game object would give an option to add waypoint objects.

  1. Add a number of waypoint for the game object that shall move.
  2. Create waypoints on desired locations.
Unity

3. Get a hold of the navmeshagent in the associated script.

C#
C#

The script has following tasks to handle.

4. The code shall be close to as followed.

C#
C#
C#
C#
  • Lastly, if there are animations made for the game object, add them as well and trigger them using the same script.
C#

That should be it :)

Here is the final result.

Thank you very much

--

--