- Home /
 
 
               Question by 
               Dawnk41 · Apr 26, 2014 at 05:09 AM · 
                navmeshagentnavigation  
              
 
              NavMeshAgent no longer moves, with new conditional destination code.
So, I recently changed my SetDestination code on my NavMeshAgent so that now, if I click on an enemy, the agent will follow that agent, and if I click on the ground, it will move to that point on the ground. Except that it just stopped moving no matter what I click on. Here is my code:
 using UnityEngine;
 using System.Collections;
 
 public class character_behaviour : MonoBehaviour
 {
     public float health = 2;
     public GameObject combatTarget;
     Vector3 target;
     NavMeshAgent agent;
     
     
     void Start ()
     {
         agent = GetComponent<NavMeshAgent>();
     }
     
     void Update ()
     {
         if (Input.GetMouseButtonDown (1))
         {
             RaycastHit mouseHit = new RaycastHit();
             Vector3 mousePos = Input.mousePosition;
             mousePos.z = 18f;
             Debug.Log(Camera.main.ScreenToWorldPoint (mousePos));
             Vector3 mouseTrue = Camera.main.ScreenToWorldPoint (mousePos);
 
             if(Physics.Raycast (Camera.main.transform.position,mouseTrue, out mouseHit) && mouseHit.transform.tag == "Terrain")
             {
             agent.SetDestination(new Vector3(mouseTrue.x, -0.45f, mouseTrue.z));
             }
             else if(Physics.Raycast (Camera.main.transform.position,mouseTrue, out mouseHit) && mouseHit.transform.tag == "Enemy")
             {
                 combatTarget = mouseHit.transform.gameObject;
             }
 
             if(combatTarget != null)
             {
                 agent.SetDestination(combatTarget.transform.position);
             }
         }
     }
 }
 
               Can anyone help me find out what is stopping it from getting a destination?
               Comment
              
 
               
              Your answer