Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Navmesh Remove in runtime

Discussion in 'Scripting' started by Gameranik, Nov 22, 2015.

  1. Gameranik

    Gameranik

    Joined:
    Nov 22, 2015
    Posts:
    2
    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);

    }
    }
    }

    }
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Gameranik likes this.
  3. Gameranik

    Gameranik

    Joined:
    Nov 22, 2015
    Posts:
    2
    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 :)
    #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);


    }
    }
    }

    }