void lookAround()
    {
        LineOfSightRotator losR = GetComponentInChildren <LineOfSightRotator>();

        lookingAround = true;
        directionsChecked++;
        if (directionsChecked > 4)
        {
            searchedAreaComplete = true;
            lookingAround        = false;
            directionsChecked    = 0;
        }
        else
        {
            losR.setRotation(90 * directionsChecked);
            StartCoroutine(checkOtherDirections(.5f));
        }
    }
 void Start()
 {
     alertState           = "patrol";
     stopped              = false;
     destination          = navPoints[0];
     currentWaypoint      = 0;
     nextWaypointDistance = 0;
     hasPathed            = false;
     seeker    = GetComponent <Seeker>();
     traveling = true;
     GetComponent <AIPath>().maxSpeed = speed;
     searchedAreaComplete             = false;
     lookingAround     = false;
     directionsChecked = 0;
     anim             = GetComponent <Animator>();
     losr             = GetComponentInChildren <LineOfSightRotator>();
     searchPointIndex = 0;
 }
    void Update()
    {
        if (stopped)
        {
            //if (alertState == 'investigate')
            //{
            //     randomized rotation logic (future commit)
            //}
            return;
        }
        if (traveling)
        {
            if (!hasPathed)
            {
                seeker.StartPath(transform.position, new Vector3(destination.x, destination.y, 0), OnPathComplete);
                hasPathed = true;
            }
            if (getCurrentPos() == destination || Vector2.Distance(getCurrentPos(), destination) < 0.1f)
            {
                traveling = false;
            }
        }
        else if (!stopped)
        {
            switch (alertState)
            {
            case "patrol":
                goToNextPoint();
                lookingAround        = false;
                searchedAreaComplete = false;
                break;

            case "investigate":
                if (searchPoints == null)
                {
                    //targetRotation = transform.rotation;
                    createSearchPoints();
                }
                break;

            case "search":
                if (!searchedAreaComplete & !lookingAround)
                {
                    Debug.Log("look around");
                    lookAround();
                }
                else if (!lookingAround)
                {
                    goToNextSearchPoint();
                    searchedAreaComplete = false;
                }
                break;
            }
        }
        if (path == null)
        {
            // We have no path to follow yet, so don't do anything
            return;
        }
        else if (currentWaypoint > path.vectorPath.Count)
        {
            return;
        }
        else if (currentWaypoint == path.vectorPath.Count)
        {
            currentWaypoint++;
            return;
        }
        // Direction to the next waypoint
        if (path != null)
        {
            Vector3 dir = (path.vectorPath[currentWaypoint] - transform.position).normalized;

            dir *= speed;
            if (!lookingAround)
            {
                if (gameObject.name.Contains("EnemyDetector"))
                {
                    int lightDirection      = getDirection(dir);
                    LineOfSightRotator loSR = GetComponentInChildren <LineOfSightRotator>();
                    if (loSR != null)
                    {
                        loSR.setRotation(lightDirection);
                    }
                }
            }
            // The commented line is equivalent to the one below, but the one that is used
            // is slightly faster since it does not have to calculate a square root
            //if (Vector3.Distance (transform.position,path.vectorPath[currentWaypoint]) < nextWaypointDistance) {
            if ((transform.position - path.vectorPath[currentWaypoint]).sqrMagnitude < nextWaypointDistance * nextWaypointDistance)
            {
                currentWaypoint++;
                return;
            }
        }
    }