Step 1: Obtain NavMesh Plus
Begin by downloading NavMesh Plus from its GitHub repository here. Once downloaded, unzip the NavMesh Plus archive.
Step 2: Integration with Your Project
Copy the entire “Navmesh components” folder from the unzipped NavMesh Plus package into the “Assets” folder of your Unity project.
Step 3: Setting Up the Ground
- Create a square 2D sprite in your Unity scene to serve as the ground. Adjust its size as needed, and feel free to change its color. To enhance clarity, rename this sprite to “ground.”
- Add a Navigation Modifier component to the “ground” object.
Step 4: Introducing Obstacles
- Populate your scene with various obstacles. Ensure these obstacles are visually distinguishable from the ground by assigning them a layer value of 1.
- For each obstacle, attach a Navigation Modifier component. Enable the “Override Area” option and choose “Not Walkable” from the Area dropdown.
Step 5: Creating a NavmeshSurface
- Insert a new empty GameObject into your scene and give it a suitable name, such as “NavmeshSurface.”
- Add two components to the “NavmeshSurface” GameObject: “Navigation CollectSources2D” and “Navigation Surface.” When adding “Navigation CollectSources2D,” select the option that includes the “Rotate Surface to XY” feature.
Step 6: Configuring NavmeshSurface
- Click the “Rotate Surface to XY” button within the “Navigation CollectSources2D” component.
- In the “Navigation Surface” component, press the “Bake” button to generate the navmesh.
Step 7: Completion
Congratulations! You have successfully set up a basic Unity 2D project with NavMesh. Your navigation mesh is now ready for use, allowing characters and objects to navigate around obstacles intelligently.
Thanks For Share !