Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.AI;
  3.  
  4. public class Wander : MonoBehaviour
  5. {
  6. [SerializeField]
  7. float speed = 20;
  8. [SerializeField]
  9. int wanderRange = 10;
  10. float directionChangeThreshold = 0.5f;
  11.  
  12. Vector3 wayPoint;
  13.  
  14. NavMeshAgent navMeshAgent;
  15.  
  16. void Start()
  17. {
  18. //initialise the target way point
  19. navMeshAgent = GetComponent<NavMeshAgent>();
  20. Move();
  21. }
  22.  
  23. void Update()
  24. {
  25. transform.position += transform.TransformDirection(Vector3.forward) * speed * Time.deltaTime;
  26. if (wayPoint.sqrMagnitude < directionChangeThreshold)
  27. {
  28. Debug.Log("Working");
  29. Move();
  30. }
  31. }
  32.  
  33. void Move()
  34. {
  35. wayPoint = Random.insideUnitSphere;
  36. navMeshAgent.SetDestination(wayPoint);
  37. print(wayPoint);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement