NavMeshObstacle turn carving off via Script

Hey. I wanted to turn off the Navmesh obstacle carving option in every GameObject with the Tag “Building3D” in the game when I press a button in the game.
so something like:

void OnClick()
	{  
       GameObject.FindGameObjectsWithTag("Building3D");
       NavMeshObstacle.carving=false;
      }

jeah… aaand. that doesent work :slight_smile: could somebody tell me why?

First you need to store all your buildings found by tag in an array. Then access NavMeshObstacle component on each of those buildings and set their carvings to be false.

Something like:

void OnClick()
{  
    GameObject[] buildings = GameObject.FindGameObjectsWithTag("Building3D");
    for(int i = 0; i < buildings.Length; i++)
    {
        buildings*.GetComponent<NavMeshObstacle>().carving = false;*

}
}
Note: The code isn’t tested but you can get the logic from it.