RandomWalk.cs 491 B

1234567891011121314151617181920212223
  1. using UnityEngine;
  2. using UnityEngine.AI;
  3. // Walk to a random position and repeat
  4. [RequireComponent(typeof(NavMeshAgent))]
  5. public class RandomWalk : MonoBehaviour
  6. {
  7. public float m_Range = 25.0f;
  8. NavMeshAgent m_Agent;
  9. void Start()
  10. {
  11. m_Agent = GetComponent<NavMeshAgent>();
  12. }
  13. void Update()
  14. {
  15. if (m_Agent.pathPending || m_Agent.remainingDistance > 0.1f)
  16. return;
  17. m_Agent.destination = m_Range * Random.insideUnitCircle;
  18. }
  19. }