2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7 KiB

5 years ago
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace Unity.FPS.AI
  4. {
  5. public class PatrolPath : MonoBehaviour
  6. {
  7. [Tooltip("Enemies that will be assigned to this path on Start")]
  8. public List<EnemyController> EnemiesToAssign = new List<EnemyController>();
  9. [Tooltip("The Nodes making up the path")]
  10. public List<Transform> PathNodes = new List<Transform>();
  11. void Start()
  12. {
  13. foreach (var enemy in EnemiesToAssign)
  14. {
  15. enemy.PatrolPath = this;
  16. }
  17. }
  18. public float GetDistanceToNode(Vector3 origin, int destinationNodeIndex)
  19. {
  20. if (destinationNodeIndex < 0 || destinationNodeIndex >= PathNodes.Count ||
  21. PathNodes[destinationNodeIndex] == null)
  22. {
  23. return -1f;
  24. }
  25. return (PathNodes[destinationNodeIndex].position - origin).magnitude;
  26. }
  27. public Vector3 GetPositionOfPathNode(int nodeIndex)
  28. {
  29. if (nodeIndex < 0 || nodeIndex >= PathNodes.Count || PathNodes[nodeIndex] == null)
  30. {
  31. return Vector3.zero;
  32. }
  33. return PathNodes[nodeIndex].position;
  34. }
  35. void OnDrawGizmosSelected()
  36. {
  37. Gizmos.color = Color.cyan;
  38. for (int i = 0; i < PathNodes.Count; i++)
  39. {
  40. int nextIndex = i + 1;
  41. if (nextIndex >= PathNodes.Count)
  42. {
  43. nextIndex -= PathNodes.Count;
  44. }
  45. Gizmos.DrawLine(PathNodes[i].position, PathNodes[nextIndex].position);
  46. Gizmos.DrawSphere(PathNodes[i].position, 0.1f);
  47. }
  48. }
  49. }
  50. }