using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class RandomKidController : MonoBehaviour {

    public List<Transform> waypoints = new List<Transform>();

    private NavMeshAgent agent;

    public void Start()
    {
        if (waypoints.Count == 0)
            gameObject.SetActive(false);

        agent = GetComponent<NavMeshAgent>();

        if (agent == null)
            Debug.LogError("Failed to find required NavMeshAgent");

        agent.destination = GetRandomWaypoint();
    }

    public void Update()
    {
        if (Vector3.Distance(agent.transform.position, agent.destination) <= 5f)
        {
            agent.destination = GetRandomWaypoint();
        }
    }

    private Vector3 GetRandomWaypoint()
    {
        return waypoints[Random.Range(0, waypoints.Count)].position;
    }
}
