Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Enemy : MonoBehaviour {
  4.  
  5. public float speed = 10f;
  6. private Transform target;
  7. private int wavepointIndex = 0;
  8.  
  9. void Start()
  10. {
  11. target = Waypoints.points[0];
  12. }
  13. void Update()
  14. {
  15. Vector3 dir = target.position - transform.position;
  16. transform.Translate(dir.normalized * speed * Time.deltaTime, Space.World);
  17.  
  18. if (Vector3.Distance(transform.position, target.position) <= 0.4f)
  19. {
  20. GetNextWaypoint();
  21. }
  22. }
  23. void GetNextWaypoint()
  24. {
  25. if(wavepointIndex >= Waypoints.points.Length - 1)
  26. {
  27.  
  28. EndPath();
  29. return;
  30. }
  31. wavepointIndex++;
  32. target = Waypoints.points[wavepointIndex];
  33. }
  34. void EndPath()
  35. {
  36. PlayerStats.Lives--;
  37. Destroy(gameObject);
  38. }
  39.  
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement