Navmesh Remove in runtime

I am made a script where a Zombie(object) is targeting nearest victim(Target).Code works for now.Now i write a script to destroy the pathway between zombie and victim in run time so zombie will find another path.But when i run the code, bridge got destroyed when i clicked but zombie still can walk on empty space and catch victim rather then finding alternative path.
What i found that destroying bridge only remove that object but navmesh still there.so i need a script so that bridge & navmesh both destroyed.
I used this script to destroy bridge >>>>>

#pragma strict

function Start () {
}

function Update () {

if (Input.GetMouseButtonDown(0)) {
Debug.Log(“End here”);
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit)) {
if (hit.collider.tag == “destroyable”) {
Destroy(hit.collider.gameObject);

}
}
}

}

Unity’s Nav mesh is not that sophisticated. You can always use a carving obstacle. http://docs.unity3d.com/ScriptReference/NavMeshObstacle.html

Or try something like Aaron Granbergs path finding project.

1 Like

Ty a lot bro.that solved my problem.I used a Navmesh obstacle & disabled it.When i destroy the bridge the script also enable the navmeshobstacle so nav agent find another way.
My new code here if any 1 need in future :slight_smile:
#pragma strict
var blocker:Transform;

function Start () {

}

function Update () {

if (Input.GetMouseButtonDown(0)) {
Debug.Log(“End here”);
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit)) {

if (hit.collider.tag == “R2”) {
Destroy(hit.collider.gameObject);
Debug.Log(“Working des”);
blocker.gameObject.SetActive(true);

}
}
}

}