Exemple #1
0
    private void Update()
    {
        // shoot handling
        WeaponController activeWeapon = GetActiveWeapon();

        if (activeWeapon && m_WeaponSwitchState == WeaponSwitchState.Up)
        {
            // handle aiming down sights
            isAiming = m_InputHandler.GetAimInputHeld();

            // handle shooting
            bool hasFired = activeWeapon.HandleShootInputs(
                m_InputHandler.GetFireInputDown(),
                m_InputHandler.GetFireInputHeld(),
                m_InputHandler.GetFireInputReleased());

            // Handle accumulating recoil
            if (hasFired)
            {
                m_AccumulatedRecoil += Vector3.back * activeWeapon.recoilForce;
                m_AccumulatedRecoil  = Vector3.ClampMagnitude(m_AccumulatedRecoil, maxRecoilDistance);
            }
        }

        // weapon switch handling
        if (!isAiming &&
            (activeWeapon == null || !activeWeapon.isCharging) &&
            (m_WeaponSwitchState == WeaponSwitchState.Up || m_WeaponSwitchState == WeaponSwitchState.Down))
        {
            int switchWeaponInput = m_InputHandler.GetSwitchWeaponInput();
            if (switchWeaponInput != 0)
            {
                bool switchUp = switchWeaponInput > 0;
                SwitchWeapon(switchUp);
            }
            else
            {
                switchWeaponInput = m_InputHandler.GetSelectWeaponInput();
                if (switchWeaponInput != 0)
                {
                    if (GetWeaponAtSlotIndex(switchWeaponInput - 1) != null)
                    {
                        SwitchToWeaponIndex(switchWeaponInput - 1);
                    }
                }
            }
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {

        if (!isGrabbed && playerInputHandler.GetInteractInputHeld())
            TryToInteact();

        else if (isGrabbed)
        {
            //if want to throw
            if (playerInputHandler.GetFireInputDown())
            {
                grabbedObject.GetComponent<Rigidbody>().AddForce(cameraGameObject.transform.forward * throwForce);
                StartCoroutine(StopGrabbing());
            }

            //if want to let go
            else if (playerInputHandler.GetAimInputHeld())
                StartCoroutine(StopGrabbing());
            else
                Grab();
        }
    }
Exemple #3
0
    private void Update()
    {
        // shoot handling
        WeaponController activeWeapon = GetActiveWeapon();

        if (activeWeapon && m_WeaponSwitchState == WeaponSwitchState.Up)
        {
            // handle aiming down sights
            isAiming = m_InputHandler.GetAimInputHeld();

            // handle shooting
            bool hasFired = activeWeapon.HandleShootInputs(
                m_InputHandler.GetFireInputDown(),
                m_InputHandler.GetFireInputHeld(),
                m_InputHandler.GetFireInputReleased());

            // Handle accumulating recoil
            if (hasFired)
            {
                m_AccumulatedRecoil += Vector3.back * activeWeapon.recoilForce;
                m_AccumulatedRecoil  = Vector3.ClampMagnitude(m_AccumulatedRecoil, maxRecoilDistance);
            }
        }

        // weapon switch handling
        if (!isAiming &&
            (activeWeapon == null || !activeWeapon.isCharging) &&
            (m_WeaponSwitchState == WeaponSwitchState.Up || m_WeaponSwitchState == WeaponSwitchState.Down))
        {
            int switchWeaponInput = m_InputHandler.GetSwitchWeaponInput();
            if (switchWeaponInput != 0)
            {
                bool switchUp = switchWeaponInput > 0;
                SwitchWeapon(switchUp);
            }
            else
            {
                switchWeaponInput = m_InputHandler.GetSelectWeaponInput();
                if (switchWeaponInput != 0)
                {
                    if (GetWeaponAtSlotIndex(switchWeaponInput - 1) != null)
                    {
                        SwitchToWeaponIndex(switchWeaponInput - 1);
                    }
                }
            }
        }

        // Pointing at enemy handling
        isPointingAtEnemy = false;
        if (activeWeapon)
        {
            if (Physics.Raycast(weaponCamera.transform.position, weaponCamera.transform.forward, out RaycastHit hit, 1000, -1, QueryTriggerInteraction.Ignore))
            {
                //if (hit.collider.GetComponentInParent<EnemyController>())
                //{
                //    isPointingAtEnemy = true;
                //}
            }
        }
    }
    private void Update()
    {
        // shoot handling
        WeaponController activeWeapon = GetActiveWeapon();

        //GUESS IS we'll only get the aim and set fired state if weapon is up aka working
        if (activeWeapon && m_WeaponSwitchState == WeaponSwitchState.Up)
        {
            // handle aiming down sights
            //GUESS: is aiming will be true if we're aiming at something in the game and we can fire at it
            isAiming = m_InputHandler.GetAimInputHeld();

            // handle shooting
            bool hasFired = activeWeapon.HandleShootInputs(
                m_InputHandler.GetFireInputDown(),
                m_InputHandler.GetFireInputHeld(),
                //TODO I thought it fires when you hold the trigger, research naming convention and meaning behind get fire input released
                m_InputHandler.GetFireInputReleased());

            // Handle accumulating recoil
            //TODO Recoil?
            if (hasFired)
            {
                m_AccumulatedRecoil += Vector3.back * activeWeapon.recoilForce;
                m_AccumulatedRecoil  = Vector3.ClampMagnitude(m_AccumulatedRecoil, maxRecoilDistance);
            }
        }

        // weapon switch handling
        if (!isAiming &&
            (activeWeapon == null || !activeWeapon.isCharging) &&
            //this condition contradicts previous assumption about weapon down meaning non fireable - TODO pin down each enums intended effect
            (m_WeaponSwitchState == WeaponSwitchState.Up || m_WeaponSwitchState == WeaponSwitchState.Down))
        {
            int switchWeaponInput = m_InputHandler.GetSwitchWeaponInput();
            if (switchWeaponInput != 0)
            {
                bool switchUp = switchWeaponInput > 0;
                SwitchWeapon(switchUp);
            }
            else
            {
                switchWeaponInput = m_InputHandler.GetSelectWeaponInput();
                if (switchWeaponInput != 0)
                {
                    if (GetWeaponAtSlotIndex(switchWeaponInput - 1) != null)
                    {
                        SwitchToWeaponIndex(switchWeaponInput - 1);
                    }
                }
            }
        }

        // Pointing at enemy handling
        isPointingAtEnemy = false;
        if (activeWeapon)
        {
            //Assumption is ray case return true if trajectory of weappon triggered projectile is expected to hit the bot
            if (Physics.Raycast(weaponCamera.transform.position, weaponCamera.transform.forward, out RaycastHit hit, 1000, -1, QueryTriggerInteraction.Ignore))
            {
                if (hit.collider.GetComponentInParent <EnemyController>())
                {
                    isPointingAtEnemy = true;
                }
            }
        }
    }
    private void Update()
    {
        //Load stuff on first frame instead of Start() to ensure required components have been initialized
        if (!isLoaded)
        {
            // Load weapons once HUD is ready
            for (int i = 0; i < m_WeaponSlots.Length; i++)
            {
                if (PlayerPrefs.HasKey($"m_WeaponSlots[{i}]"))
                {
                    var        weaponName   = PlayerPrefs.GetString($"m_WeaponSlots[{i}]");
                    GameObject weaponPrefab = WeaponGenerator.getWeaponGameObject(weaponName);
                    if (weaponPrefab)
                    {
                        WeaponController weaponController =
                            (WeaponController)weaponPrefab.GetComponentInChildren(typeof(WeaponController));
                        AddWeapon(weaponController, weaponName);
                    }
                }
            }

            if (!hasWeapons)
            {
                var        weaponName   = "milk";
                GameObject weaponPrefab = WeaponGenerator.getWeaponGameObject(weaponName);
                if (weaponPrefab)
                {
                    WeaponController weaponController =
                        (WeaponController)weaponPrefab.GetComponentInChildren(typeof(WeaponController));
                    AddWeapon(weaponController, weaponName);
                }
            }

            if (PlayerPrefs.HasKey("activeWeaponIndex"))
            {
                SwitchToWeaponIndex(PlayerPrefs.GetInt("activeWeaponIndex"));
            }
            else
            {
                SwitchWeapon(true);
            }

            isLoaded = true;
        }

        // shoot handling
        WeaponController activeWeapon = GetActiveWeapon();

        if (activeWeapon && m_WeaponSwitchState == WeaponSwitchState.Up)
        {
            // handle aiming down sights
            isAiming = m_InputHandler.GetAimInputHeld();

            // handle shooting
            bool hasFired = activeWeapon.HandleShootInputs(
                m_InputHandler.GetFireInputDown(),
                m_InputHandler.GetFireInputHeld(),
                m_InputHandler.GetFireInputReleased());

            // Handle accumulating recoil
            if (hasFired)
            {
                m_AccumulatedRecoil += Vector3.back * activeWeapon.recoilForce;
                m_AccumulatedRecoil  = Vector3.ClampMagnitude(m_AccumulatedRecoil, maxRecoilDistance);
            }
        }

        // weapon switch handling
        if (!isAiming &&
            (activeWeapon == null || !activeWeapon.isCharging) &&
            (m_WeaponSwitchState == WeaponSwitchState.Up || m_WeaponSwitchState == WeaponSwitchState.Down))
        {
            int switchWeaponInput = m_InputHandler.GetSwitchWeaponInput();
            if (switchWeaponInput != 0)
            {
                bool switchUp = switchWeaponInput > 0;
                SwitchWeapon(switchUp);
            }
            else
            {
                switchWeaponInput = m_InputHandler.GetSelectWeaponInput();
                if (switchWeaponInput != 0)
                {
                    if (GetWeaponAtSlotIndex(switchWeaponInput - 1) != null)
                    {
                        SwitchToWeaponIndex(switchWeaponInput - 1);
                    }
                }
            }
        }

        // Pointing at enemy handling
        isPointingAtEnemy = false;
        if (activeWeapon)
        {
            if (Physics.Raycast(weaponCamera.transform.position, weaponCamera.transform.forward, out RaycastHit hit, 1000, -1, QueryTriggerInteraction.Ignore))
            {
                if (hit.collider.GetComponentInParent <EnemyController>())
                {
                    isPointingAtEnemy = true;
                }
            }
        }

        WeaponDropper();
    }
    private void Update()
    {
        // shoot handling
        //撮影処理
        WeaponController activeWeapon = GetActiveWeapon();

        if (activeWeapon && m_WeaponSwitchState == WeaponSwitchState.Up)
        {
            // handle aiming down sights
            //下向きの照準を処理します
            isAiming = m_InputHandler.GetAimInputHeld();

            // handle shooting
            //射撃を処理する
            bool hasFired = activeWeapon.HandleShootInputs(
                m_InputHandler.GetFireInputDown(),
                m_InputHandler.GetFireInputHeld(),
                m_InputHandler.GetFireInputReleased());

            // Handle accumulating recoil
            //蓄積された反動を処理します
            if (hasFired)
            {
                m_AccumulatedRecoil += Vector3.back * activeWeapon.recoilForce;
                //蓄積反動 += 3Dベクトルを返す。* アクティブな武器.反動力;
                m_AccumulatedRecoil = Vector3.ClampMagnitude(m_AccumulatedRecoil, maxRecoilDistance);
                //蓄積反動 = 3Dベクトル。 クランプの大きさ(累積反動、最大反動距離);
            }
        }

        // weapon switch handling
        //武器切り替え処理
        if (!isAiming &&
            (activeWeapon == null || !activeWeapon.isCharging) &&
            (m_WeaponSwitchState == WeaponSwitchState.Up || m_WeaponSwitchState == WeaponSwitchState.Down))
        {
            int switchWeaponInput = m_InputHandler.GetSwitchWeaponInput();
            if (switchWeaponInput != 0)
            {
                bool switchUp = switchWeaponInput > 0;
                SwitchWeapon(switchUp);
            }
            else
            {
                switchWeaponInput = m_InputHandler.GetSelectWeaponInput();
                if (switchWeaponInput != 0)
                {
                    if (GetWeaponAtSlotIndex(switchWeaponInput - 1) != null)
                    {
                        SwitchToWeaponIndex(switchWeaponInput - 1);
                    }
                }
            }
        }

        // Pointing at enemy handling
        //敵の扱いを指さす
        isPointingAtEnemy = false;
        //敵を指している = 非表示
        if (activeWeapon)
        //もし、アクティブな武器
        {
            if (Physics.Raycast(weaponCamera.transform.position, weaponCamera.transform.forward, out RaycastHit hit, 1000, -1, QueryTriggerInteraction.Ignore))
            //もし(物理レイキャスト(武器カメラ.変換.位置, 武器カメラ.変換.先端,外レイキャストヒット, 1000,-1,クエリはトリガーの発生を報告しません))
            {
                if (hit.collider.GetComponentInParent <EnemyController>())
                //もし(ヒット.コライダー.コンポーネントを親から取得<EnemyController>)
                {
                    isPointingAtEnemy = true;
                    //敵を指している = 表示
                }
            }
        }
    }
Exemple #7
0
    void Update()
    {
        if (m_InputHandler.GetAimInputHeld())
        {
            if (playerCamera.fieldOfView > 40.3f)
            {
                playerCamera.fieldOfView -= 0.3f;
            }
        }
        else
        {
            if (playerCamera.fieldOfView < 60.3f)
            {
                playerCamera.fieldOfView += 0.3f;
            }
        }

        if (vignette != null)
        {
            if (isCrouching && vignette.weight < 1)
            {
                vignette.weight += 0.01f;

                if (vignette.weight > 1)
                {
                    vignette.weight = 1;
                }
            }

            if (!isCrouching && vignette.weight > 0.0f)
            {
                vignette.weight -= 0.005f;

                if (vignette.weight < 0)
                {
                    vignette.weight = 0;
                }
            }
        }

        hasJumpedThisFrame = false;

        bool wasGrounded = isGrounded;

        GroundCheck();

        if (isGrounded && !wasGrounded)
        {
            float fallSpeed      = -Mathf.Min(characterVelocity.y, m_LatestImpactSpeed.y);
            float fallSpeedRatio = (fallSpeed - minSpeedForFallDamage) / (maxSpeedForFallDamage - minSpeedForFallDamage);
            if (recievesFallDamage && fallSpeedRatio > 0f)
            {
                // audioSource.PlayOneShot(fallDamageSFX);
            }
            else
            {
                audioSource.PlayOneShot(landSFX);
            }
        }

        if (m_InputHandler.GetFlashlightInputDown())
        {
            if (!flashlight.enabled)
            {
                flashlightOff.Play();
            }
            else
            {
                flashlightOn.Play();
            }
            flashlight.enabled = !flashlight.enabled;
        }

        if (m_InputHandler.GetCrouchInputDown())
        {
            SetCrouchingState(!isCrouching, false);
        }

        UpdateCharacterHeight(false);

        HandleCharacterMovement();
    }