示例#1
0
    /// <summary>
    /// Handles combat input.
    /// </summary>
    private void Update()
    {
        // allows the player to break out into scene view
        if (Input.GetButtonDown("Exit"))
        {
            Debug.Break();
        }

        // checks if the player is now aiming
        if (Input.GetButtonDown("Aim"))
        {
            cameraSettings.aiming = true;

            // sets the animation to aiming
            m_anim.SetBool("Aim", true);
            m_anim.SetLayerWeight(1, 0.0f);
            m_anim.SetLayerWeight(2, 1.0f);
            combatSettings.crosshairObject.GetComponent <Animator>().SetBool("Aim", true);

            // moves the player to the direction the camera is pointing
            transform.rotation = Quaternion.Euler(new Vector3(transform.localEulerAngles.x, cameraSettings.freeCamera.m_XAxis.Value, transform.localEulerAngles.z));
            cameraSettings.ResetPlayerRotation();

            // transitions from the free camera to the over the shoulder camera
            cameraSettings.overShoulderCamera.gameObject.SetActive(true);
            cameraSettings.overShoulderCamera.m_XAxis.Value = cameraSettings.freeCamera.m_XAxis.Value;
            cameraSettings.overShoulderCamera.m_YAxis.Value = cameraSettings.freeCamera.m_YAxis.Value;
            cameraSettings.freeCamera.gameObject.SetActive(false);
        }
        // checks if the player is no long aiming
        else if (Input.GetButtonUp("Aim"))
        {
            cameraSettings.aiming = false;

            // sets the animation to not aiming if the player is not shooting
            if (combatSettings.combatState != PlayerCombat.CombatState.Shooting)
            {
                m_anim.SetBool("Aim", false);
                m_anim.SetLayerWeight(1, 1.0f);
                m_anim.SetLayerWeight(2, 0.0f);
            }
            else
            {
                cameraSettings.previousRot = transform.localRotation;
            }
            combatSettings.crosshairObject.GetComponent <Animator>().SetBool("Aim", false);

            // transitions from the over the shoulder camera to the free camera
            cameraSettings.freeCamera.gameObject.SetActive(true);
            cameraSettings.freeCamera.m_XAxis.Value = cameraSettings.overShoulderCamera.m_XAxis.Value;
            cameraSettings.freeCamera.m_YAxis.Value = cameraSettings.overShoulderCamera.m_YAxis.Value;
            cameraSettings.overShoulderCamera.gameObject.SetActive(false);
        }

        // determines the current combat state
        combatSettings.ChargeShot();
        // rotates the camera based on the player
        RotateView();
    }