Exemplo n.º 1
0
    void Update()
    {
        if (!playerAnimate.Crouching())
        {
            foreach (GameObject crouchable in crouchables)
            {
                crouchable.layer = 10;
            }
        }
        else if (player.GetComponentInChildren <PlayerAnimate>().Crouching())
        {
            foreach (GameObject crouchable in crouchables)
            {
                crouchable.layer = 8;
            }
        }



        if (!onPatrol)
        {
            backToPoint = true;
            FollowPlayer();
        }
        // Choose the next destination point when the agent gets
        // close to the current one.
        if (onPatrol)
        {
            attackingPlayer = false;
            StartCoroutine(CheckMoving());
            if (backToPoint)
            {
                GotoNextPoint();
                backToPoint = false;
            }

            if (!navAgent.pathPending && navAgent.remainingDistance < 0.5f)
            {
                GotoNextPoint();
            }
        }

        if (CanSeePlayer())
        {
            onPatrol        = false;
            spotlight.color = originalLightColor;
            returnTimer     = 5;
            attackingPlayer = true;
        }
        if (!CanSeePlayer())
        {
            if (!onPatrol)
            {
                returnTimer -= Time.deltaTime;
                if (returnTimer <= 0)
                {
                    onPatrol        = true;
                    spotlight.color = Color.yellow;
                }
            }

            if (spottedUnconscious && onPatrol)
            {
                //onPatrol = false;
                navAgent.stoppingDistance = 2f;
                navAgent.SetDestination(unconsciousGuard.transform.position);
                Quaternion targetRotation = Quaternion.LookRotation(unconsciousGuard.transform.position - transform.position);
                //Smoothly rotate towards the target point.
                transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, turnSpeed * Time.deltaTime);
                if (!unconsciousGuard.GetComponent <GuardUnconscious>().isUnconscious())
                {
                    navAgent.stoppingDistance = 0f;
                    spottedUnconscious        = false;
                    onPatrol = true;
                }
            }
        }
    }