333GameStudio

Enemy

Sep 27th, 2015
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.  
  3. var target : Transform;
  4. var navComponent : NavMeshAgent;
  5. var MaxDist : float = 5;
  6.  
  7. function Start () {
  8. target = GameObject.FindWithTag("Player").transform;
  9.         navComponent = this.transform.GetComponent(NavMeshAgent);
  10. }
  11.  
  12. function Update () {
  13.  if (target) {
  14.         var dist = Vector3.Distance(target.position, transform.position);
  15.         if (dist < MaxDist){
  16.         if(target) {
  17.        
  18.                 navComponent.SetDestination(target.position);  
  19.                
  20.         }
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment