Example #1
0
    // Update is called once per frame
    void Update()
    {
        //Draw Field of View
        fOV.DrawFieldOfView();

        //Check if player in view
        if (fOV.PlayerInView())
        {
            playerInSight = true; print("INVIEW");
        }
        else
        {
            playerInSight = false;
        }

        //IF player in view, chase player
        if (playerInSight)
        {
            chasing = true;
            print("I see player");
            chase.MoveToLastKnownPosition(fOV.GetLastKnownPosition());
        }
        //If chasing player and lost player
        if (chasing && !playerInSight)
        {
            scanning = true;
            //continue to players last known position
            print("Going to last known");

            Vector3 lastKnow = fOV.GetLastKnownPosition();
            chase.MoveToLastKnownPosition(lastKnow);

            //scan the area
            print("Scanning area");
            if (transform.position.x == lastKnow.x && transform.position.z == lastKnow.z)
            {
                print("At Last Known pos");
                agent.isStopped = true;

                //Rotate to look around
                if (!rotating)
                {
                    StartRotation();
                }

                if (!waiting)
                {
                    waiting = true;
                    StartCoroutine(Wait());
                }
            }
        }

        //else patrol the map
        if (!playerInSight && !chasing && !scanning)
        {
            //print("Patroling");
            patrol.MoveToPoint();
        }
    }