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.
- The waypoints in Unity are game objects with only a transform component. To store them in an efficient structure, List seems an ideal choice.
As soon as the script is loaded, the script component on the game object would give an option to add waypoint objects.
- Add a number of waypoint for the game object that shall move.
- Create waypoints on desired locations.
3. Get a hold of the navmeshagent in the associated script.
The script has following tasks to handle.
4. The code shall be close to as followed.
- Lastly, if there are animations made for the game object, add them as well and trigger them using the same script.
That should be it :)
Here is the final result.
Thank you very much