Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IEnumerator MoveRandomPos()
- {
- while(true){
- yield return null;
- RaycastHit hit;
- Ray ray = new Ray(transform.position, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f) * transform.forward);
- /*Debug.DrawRay(transform.position, ray.direction, Color.red, 3f);*/
- if (Physics.Raycast(ray, out hit))
- {
- if (hit.distance > 2f)
- {
- yield return StartCoroutine(MoveToPos(ray.direction));
- yield return new WaitForSeconds(Random.Range(4f, 7f));
- }
- }
- }
- }
- IEnumerator MoveToPos(Vector3 direction){
- nav.SetDestination(direction);
- var startPos = nav.transform.position;
- var randomDistance = Random.Range(4f, 7f);
- yield return new WaitUntil(()=> Vector3.Distance(startPos, nav.position) >= randomDistance);
- }
Add Comment
Please, Sign In to add comment