Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. public static GameObject way_point1;
  2. public static GameObject way_point2;
  3.  
  4. void Start()
  5. {
  6. //это внутри GameObjectStartLevel
  7. prefab = Resources.Load("prefabs/way_point");
  8. way_point1 = Instantiate(prefab) as GameObject;
  9. //go_sp.AddComponent<Rigidbody>();
  10. x = 390;
  11. y = 10;
  12. z = 256;
  13. vector3 = new Vector3(x, y, z);
  14. way_point1.transform.position = vector3;
  15.  
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Text;
  20. using UnityEngine;
  21.  
  22. namespace Assets.scripts.core.ai
  23. {
  24. public class PathAA : MonoBehaviour
  25. {
  26. NavMeshAgent agent;
  27.  
  28. //CharMove charMove;
  29.  
  30. //хранит папку точек
  31. //public GameObject waypointHolder;
  32. //занесение точек в лист
  33. public List<Transform> waypoints = new List<Transform>();
  34. //the next waypoint should have a longerdistance than the target tolerance
  35. float targetTolerance = 1;
  36. public int waypointIndex;
  37. Vector3 targetPos;
  38. Animator anim;
  39. public float waitingTime = 0;
  40. float patrolTimer;
  41. ////
  42. private void Start()
  43. {
  44. mob_action = "go_exit";
  45.  
  46. ////
  47. //Setup the references
  48. agent = GetComponentInChildren<NavMeshAgent>();
  49. //charMove = GetComponent<CharMove>();
  50. //anim = GetComponent<Animator>();
  51.  
  52. //Get all our waypoints
  53. //здесь GameObjectStartLevel
  54. waypoints.Add(GameObjectStartLevel.way_point1.transform);
  55. waypoints.Add(GameObjectStartLevel.way_point2.transform);
  56.  
  57. void Update()
  58. {
  59. Patrolling();
  60. }
  61.  
  62. /*The patrol function is simple
  63. we check if we reach one waypoint, we wait a bit, then go to the next one
  64. */
  65.  
  66. void Patrolling() //cостояние патруль
  67. {
  68. agent.speed = 10;
  69.  
  70. if (waypoints.Count > 0)
  71. {
  72. //заменить на коллайдер
  73. if (agent.remainingDistance < agent.stoppingDistance)
  74. {
  75. patrolTimer += Time.deltaTime;
  76.  
  77. if (patrolTimer >= waitingTime)
  78. {
  79. if (waypointIndex == waypoints.Count - 1)
  80. {
  81. waypointIndex = 0;
  82. }
  83. else
  84. {
  85. waypointIndex++;
  86. }
  87. patrolTimer = 0;
  88. }
  89. }
  90. MoveTo(waypoints[waypointIndex].position, false, targetPos);
  91. }
  92. }
  93.  
  94.  
  95.  
  96. //Because we are going to use following code a lot, we made it into a function to save time
  97. void MoveTo(Vector3 destination, bool aim, Vector3 lookPos)
  98. {
  99. agent.transform.position = transform.position;
  100.  
  101. agent.destination = destination;
  102.  
  103. Vector3 velocity = agent.desiredVelocity * 0.5f;
  104.  
  105. //charMove.Move(velocity, aim, lookPos);
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement