Ejemplo n.º 1
0
    private IEnumerator WakeUp()
    {
        state = Camera_state.WAKING_UP;
        yield return(new WaitForSeconds(LookDelay * worldState.GetDetectionTime() / originalLookTime));

        state = Camera_state.FOLLOWING;
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
//		Debug.Log (state);
        //INSERT COLLIDER CHECK HERE
        if (cameraFOV.hasPlayer)
        {
            playerLocation = cameraFOV.playerLocation;
            Debug.DrawRay(transform.position, (playerLocation - transform.position).normalized * _DetectionDistance, Color.red);
            Physics.Raycast(transform.position, (playerLocation - transform.position), out hit, _DetectionDistance, _mask.value);
            if (hit.collider != null && hit.collider.gameObject.tag == "Player")
            {
                if (state != Camera_state.FOLLOWING && state != Camera_state.WAKING_UP)
                {
                    StartCoroutine(WakeUp());
                }
            }
            else
            {
                state = Camera_state.ASLEEP;
            }
        }
        else
        {
            state = Camera_state.ASLEEP;
        }

        if (state == Camera_state.ASLEEP)
        {
            Quaternion targetAngle = Quaternion.AngleAxis(targetRotationY, Vector3.up) * start_rotation;
            transform.rotation = Quaternion.Lerp(transform.rotation, targetAngle, Time.deltaTime);
            if (Quaternion.Angle(targetAngle, transform.rotation) <= .05f)
            {
                targetRotationY *= -1;
            }
        }
        else if (state == Camera_state.FOLLOWING)
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(playerLocation - transform.position), Time.deltaTime);
            worldAIHandler.AlertEnemies(playerLocation);
        }
    }