Search Unity

How to stop a running script.

Discussion in 'Navigation' started by blackflag, Jan 25, 2015.

  1. blackflag

    blackflag

    Joined:
    Jan 25, 2015
    Posts:
    1
    Hi guys this is my first post on unity forum. i really need help on this one
    so i made a script that makes my navMeshAgent go to a game object called victim. now my problem is that even if the navMeshAgent reaches the position of the victim. the script wont just stop even though i made it to stop ones its gets to the victim.position.

    What i wanted is that when the navMeshAgent reaches victim.position, the script itself would stop.

    please help me guys

    #pragma strict

    public var victim : Transform;
    private var navComponent : NavMeshAgent;
    var scriptIsActive : boolean = false;

    function Start () {

    if(!scriptIsActive){
    navComponent = this.transform.GetComponent(NavMeshAgent);
    }
    }

    function OnGUI () {
    if(!scriptIsActive){
    navComponent.SetDestination(victim.position);
    }
    }

    function Update(){
    if(navComponent==victim.position)
    {
    GetComponent(sample2).enabled = false;
    }
    }
     
  2. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,357
    Don't really understand java or c# for that matter but if u want the object to stop moving at destination just set object.speed to 0.
     
  3. OrigamiWolf

    OrigamiWolf

    Joined:
    Jul 23, 2014
    Posts:
    1
    I'm unclear what in what you want to do. Do you want to stop the character from moving when they reach their destination or disable the entire script?