Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.AI;
- public class Wander : MonoBehaviour
- {
- [SerializeField]
- float speed = 20;
- [SerializeField]
- int wanderRange = 10;
- float directionChangeThreshold = 0.5f;
- Vector3 wayPoint;
- NavMeshAgent navMeshAgent;
- void Start()
- {
- //initialise the target way point
- navMeshAgent = GetComponent<NavMeshAgent>();
- Move();
- }
- void Update()
- {
- transform.position += transform.TransformDirection(Vector3.forward) * speed * Time.deltaTime;
- if (wayPoint.sqrMagnitude < directionChangeThreshold)
- {
- Debug.Log("Working");
- Move();
- }
- }
- void Move()
- {
- wayPoint = Random.insideUnitSphere;
- navMeshAgent.SetDestination(wayPoint);
- print(wayPoint);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement