SHARE
TWEET

Untitled

a guest Jan 12th, 2017 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public Transform final;
  2.     public GameObject[] ftarget;
  3.     NavMeshAgent agent;
  4.     NavMeshPath path;
  5.     public bool findtarget;
  6.     // Use this for initialization
  7.     void Start () {
  8.         agent = GetComponent<NavMeshAgent>();
  9.         path = new NavMeshPath();
  10.         ftarget = GameObject.FindGameObjectsWithTag("CastleRed");
  11.         //ftarget = GameObject.FindGameObjectWithTag("CastleRed").transform;
  12.        
  13.     }
  14.    
  15.     // Update is called once per frame
  16.     void Update () {
  17.  
  18.         if (!final)
  19.         {
  20.             foreach (GameObject ft in ftarget)
  21.             {
  22.  
  23.                 agent.CalculatePath(ft.transform.position, path);
  24.                 if(path.status == NavMeshPathStatus.PathComplete)
  25.                 {
  26.                     final = ft.transform;
  27.                 }
  28.                
  29.             }
  30.         }
  31.         else
  32.         {
  33.             agent.SetDestination(final.transform.position);
  34.         }
  35.        
  36.      
  37.  
  38.     }
  39. }
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top