Advertisement
Guest User

Enemyfollow

a guest
Oct 16th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class EnemyFollow : MonoBehaviour
  6. {
  7. public float speed;
  8. static public bool visable = false;
  9.  
  10. private Transform target;
  11. // Start is called before the first frame update
  12. void Start()
  13. {
  14.  
  15. }
  16.  
  17. // Update is called once per frame
  18. void Update()
  19. {
  20. if (visable)
  21. {
  22. target = enemyShooterTrigger.target;
  23.  
  24. if (Vector2.Distance(transform.position, target.position) > 2)
  25. {
  26. transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
  27. Vector2 direction = (target.position - transform.position).normalized;
  28. transform.up = direction;
  29. }
  30. }
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement