Spawn and Place NavMeshAgents on a NavMesh at Runtime | AI Series Part 4 | Unity Tutorial

Опубликовано: 02 Октябрь 2024
на канале: LlamAcademy
22,425
374

In this tutorial I show you how to dynamically spawn NavMeshAgents into your scene at runtime, at a random position on the NavMesh. We utilize NavMeshTriangulation and NavMesh.SamplePosition to find a valid location on the NavMesh, and spawn them from our Object Pool in a Coroutine.

👨‍💻 As always, all code from this video is available on GitHub: https://github.com/llamacademy/ai-ser...
This project is the *END STATE* of this tutorial. You can (mostly, in this case, the scene is different) follow along by opening the PREVIOUS project (https://github.com/llamacademy/ai-ser...)

🏷️Save 25% on the ultimate C# IDE: JetBrains Rider with code LLAMACADEMY: https://www.jetbrains.com/store/?sect...

📚 Resources
⚫ If you are not familiar with Coroutines, check out the Introduction to Coroutines Video:    • Introduction to Coroutines in Unity. ...  
⚫ If you are not familiar with Object Pooling, check out the Introduction to Object Pooling in Unity video:    • Introduction to Object Pooling in Uni...  

As usual with the AI Series, we're using the NavMesh Components: https://docs.unity3d.com/Manual/NavMe... not the built-in navigation system.

🧡 Believe in LlamAcademy's mission and have received value from the videos? Here's how you can show your support:
🌟 Patreon:   / llamacademy  
🌟 YouTube Member:    / @llamacademy   or click the Join button on any video
📚 Take my Unity ShaderGraph Course:
https://www.gamedev.tv/p/unity-shader...
👕 Get yourself some LlamAcademy merch: https://llamacademy.myspreadshop.com/
💸 Use my Affiliate Link for Humble Bundles https://humblebundleinc.sjv.io/9g4ak4
💸 Publisher Sale! 50% OFF an entire publisher's Assets! Publisher changes weekly! https://assetstore.unity.com/publishe... (affiliate)
💸 Save up to 50% on NEW Assets: https://assetstore.unity.com/?new_sal... (affiliate)

Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.

Chapters:
00:00 Intro
01:09 Scene Changes Overview and Script Organization
02:24 Enemy Script
02:42 Enemy Spawner Script
07:20 Enemy Movement Updates
08:13 Final Enemy Spawner Changes
09:04 Enemy Script Poolable Object Handling
09:34 Scene and Prefab Setup
10:17 Demo
10:41 Closing