SHARE
TWEET

Untitled

jairogv98 Dec 14th, 2019 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class EnemyController : MonoBehaviour
  2. {
  3.     private Animator myAnim;
  4.     private Transform target;
  5.  
  6.     [SerializeField]
  7.     private float speed;
  8.     [SerializeField]
  9.     private float maxRange;
  10.     [SerializeField]
  11.     private float minRange;
  12.  
  13.  
  14.     void Start()
  15.     {
  16.         myAnim = GetComponent<Animator>();
  17.         target = FindObjectOfType<Player>().transform;
  18.  
  19.     }
  20.  
  21.  
  22.     void Update()
  23.     {
  24.         if(Vector3.Distance(target.position, transform.position)<= maxRange&&Vector3.Distance(target.position, transform.position)>=minRange)
  25.         {
  26.             FollowPlayer();
  27.         }
  28.        
  29.    
  30.     }
  31.  
  32.     public void FollowPlayer()
  33.     {
  34.  
  35.         transform.position = Vector3.MoveTowards(transform.position, target.transform.position, speed * Time.deltaTime);
  36.  
  37.     }
  38.  
  39.    
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top