示例#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);
                    }
                }
            }
        }
    }
    private void Update()
    {
        // handle shooting
        SpellController basicSpell = m_SpellSlots[basicSpellIndex];

        basicSpell.HandleShootInputs(
            m_InputHandler.GetFireInputDown(),
            m_InputHandler.GetFireInputHeld(),
            m_InputHandler.GetFireInputReleased());

        SpellController altSpell = m_SpellSlots[altSpellIndex];

        altSpell.HandleShootInputs(
            m_InputHandler.GetAltInputDown(),
            m_InputHandler.GetAltInputHeld(),
            m_InputHandler.GetAltInputReleased());

        SpellController utilitySpell = m_SpellSlots[utilitySpellIndex];

        utilitySpell.HandleShootInputs(
            m_InputHandler.GetUtilityInputDown(),
            m_InputHandler.GetUtilityInputHeld(),
            m_InputHandler.GetUtilityInputReleased());

        SpellController ultimateSpell = m_SpellSlots[ultimateSpellIndex];

        ultimateSpell.HandleShootInputs(
            m_InputHandler.GetUltimateInputDown(),
            m_InputHandler.GetUltimateInputHeld(),
            m_InputHandler.GetUltimateInputReleased());

        SpellController interactSpell = interactionController;

        interactSpell.HandleShootInputs(
            m_InputHandler.GetInteractInputDown(),
            m_InputHandler.GetInteractInputHeld(),
            m_InputHandler.GetInteractInputReleased());

        // Pointing at enemy handling
        // isPointingAtEnemy = false;
        // if(Physics.Raycast(SpellCamera.transform.position, SpellCamera.transform.forward, out RaycastHit hit, 1000, -1, QueryTriggerInteraction.Ignore))
        // {
        //     if(hit.collider.GetComponentInParent<EnemyCharacterController>())
        //     {
        //         isPointingAtEnemy = true;
        //     }
        // }
    }
示例#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;
                //}
            }
        }
    }
示例#4
0
 // Update is called once per frame
 void Update()
 {
     HandleCharacterMovement();
     HandleShooting(m_InputHandler.GetFireInputDown(), m_InputHandler.GetFireInputHeld(), m_InputHandler.GetFireInputReleased());
 }
    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;
                    //敵を指している = 表示
                }
            }
        }
    }
示例#8
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());

            bool hasAltFired = activeWeapon.HandleAltShootInputs(
                m_InputHandler.GetAltFireInputDown(),
                m_InputHandler.GetAltFireInputHeld(),
                m_InputHandler.GetAltFireInputReleased());

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

            // tell weaponcontroller to use lightning VFX
            if (m_InputHandler.GetFireInputDown())
            {
                activeWeapon.SetFX(true);
            }
            else if (m_InputHandler.GetFireInputReleased())
            {
                activeWeapon.SetFX(false);
            }
        }

        // 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;
                }
            }
        }

        // Selectable handling
        Collider selectableCollider = RaycastForSelectableCollider();

        if (selectableCollider)
        {
            Selectable selectable = selectableCollider.gameObject.GetComponentInParent <Selectable>();
            //if pointing at a selectable and it hasn't been selected, select it and unselect the last used selectable
            if (!selectable.selected)
            {
                // Debug.Log("select");
                selectable.Select(GetComponent <PlayerUpgradeManager>());
                m_LastSelectable = selectable;
            }
        }
        else if (m_LastSelectable)
        {
            //if not pointing at a selectable and we were in the last frame, then unset m_lastselectable and unselect it
            m_LastSelectable.Unselect();
            m_LastSelectable = null;
        }
    }