Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.AI;
- public class Wander : MonoBehaviour
- {
- [SerializeField]
- float Speed = 20;
- Vector3 wayPoint;
- [SerializeField]
- int Range = 10;
- void Start()
- {
- //initialise the target way point
- wander();
- }
- void Update()
- {
- // this is called every frame
- // do move code here
- transform.position += transform.TransformDirection(Vector3.forward) * Speed * Time.deltaTime;
- if ((transform.position - wayPoint).magnitude < 3)
- {
- // when the distance between us and the target is less than 3
- // create a new way point target
- { Debug.Log("Working"); wander(); }
- wander();
- }
- }
- void wander() {
- wayPoint = Random.insideUnitSphere * Range ;
- GetComponent<NavMeshAgent>().SetDestination(wayPoint);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement