コード例 #1
0
    void Reload()
    {
        if (_gunInventory[_currentlySelectedWeapon].gunObject && !_grenadeSelected && _currentlySelectedWeapon != 2)
        {
            if (_currentWeaponInterface.returnCurrentMagazineValue() == 0)
            {
                RemoveCritBoost();
            }


            bool fullMagazine = _currentWeaponInterface.returnCurrentMagazineValue() == _currentWeaponInterface.ReturnClipSize();
            if (XCI.GetButtonDown(XboxButton.X, _inputScript.controller) && !fullMagazine && _gunInventory[_currentlySelectedWeapon].currentAmmo > 0)
            {
                GetComponent <SCR_PlayerWorldSpaceUI>().ShowReloadPrompt(true);
                if (!_isReloading)
                {
                    if (bCritActive)
                    {
                        RemoveCritBoost();
                    }
                    critGauge    = null;
                    _isReloading = true;
                    _currentWeaponInterface.GunReload(true);
                    normalGauge = uiManagerScript.DecreaseSteamGauge(gameObject.tag, this, reloadMultiplier, playerWorldSpaceUIScr);
                    _currentWeaponInterface.PlayReloadSound();
                    StartCoroutine(normalGauge);

                    if (!bHasReloaded && bTutorialCanReload)
                    {
                        GameObject tutorialManager = GameObject.FindGameObjectWithTag("TutorialManager");
                        if (tutorialManager)
                        {
                            SCR_TutorialManager tutorialManagerScr = tutorialManager.GetComponent <SCR_TutorialManager>();
                            tutorialManagerScr.SetHasReloaded();
                        }
                        bHasReloaded = true;
                    }

                    playerWorldSpaceUIScr.HideReloadButtonPrompt();
                }
                else if (_isReloading && !_CritAttempted)
                {
                    if (normalGauge != null)
                    {
                        StopCoroutine(normalGauge);
                        normalGauge = null;
                    }

                    critGauge = uiManagerScript.rotateGaugePinFull(0.0f, this, gameObject.tag, false);
                    StartCoroutine(critGauge);


                    playerWorldSpaceUIScr.ShowReloadPrompt(false);
                    //Original system
                    //float clipPercentage = uiManagerScript.ReturnPercentage(gameObject.tag);
                    //float ammoGaugePercentage = RefillClip(clipPercentage);


                    //EGX SYSTEM
                    float ammoGaugePercentage = RefillClip(100);


                    _CritAttempted = true;
                    uiManagerScript.SetCurrentAmmoText(gameObject.tag, ammoGaugePercentage * _currentWeaponInterface.ReturnClipSize(), _gunInventory[_currentlySelectedWeapon].currentAmmo, _currentWeaponInterface.ReturnClipSize());

                    if (uiManagerScript.WithinCritZone())
                    {
                        CriticalDamageBonus();
                        SCR_AudioManager.instance.Play("DingReload");
                    }
                }
            }
        }
    }
コード例 #2
0
    public bool Fire()
    {
        bool bulletFired = false;

        if (bulletTimer <= 0 && _currentClip > 0 && !isReloading)
        {
            RaycastHit hitCamera;

            Vector3 pointTowards = new Vector3();
            pointTowards = transform.position + (transform.right * 9999);
            Vector3 direction = _gunPosition.position + transform.right;
            direction.y = transform.position.y;
            direction   = direction - transform.position;



            if (Physics.Raycast(transform.position, direction.normalized, out hitCamera, Mathf.Infinity, hitDetectionLayerMask, QueryTriggerInteraction.Ignore))
            {
                pointTowards = hitCamera.point;
            }

            pointTowards = GetShotPosAfterSpread(pointTowards, _gunValues.ACCURACY);

            Shoot(pointTowards);

            if (!IsInfinitePistol)
            {
                _currentClip--;
            }

            if (_playerParent)
            {
                if (!IsInfinitePistol)
                {
                    SCR_UIManager.instance.SetCurrentAmmoText(_playerParent.tag, _currentClip, -1, _gunValues.CLIPSIZE);
                }
                else
                {
                    SCR_UIManager.instance.SetCurrentAmmoText(_playerParent.tag, _currentClip, -1, _gunValues.CLIPSIZE, true);
                }
            }

            bulletTimer = (1 / (_gunValues.RATEOFFIRE)) * 5.0f;
            currentMuzzle.SetActive(true);

            //currentMuzzle.transform.LookAt(pointTowards);
            //currentMuzzle.transform.Rotate(Vector3.up, -90.0f);

            Invoke("DeactivateMuzzleEffect", 0.1f);
            currentGunShotSource.pitch = Random.Range(lowerPitchValue, higherPitchValue);
            currentGunShotSource.PlayOneShot(RetreiveGunShot(), currentGunShotSource.volume);
            bulletFired = true;
        }

        if (bulletTimer <= 0 && _currentClip <= 0 && !isReloading)
        {
            int weaponSlot = 0;
            switch (_gunValues.SLOTTYPE)
            {
            case GunTypes.Primary: weaponSlot = 0; break;

            case GunTypes.Secondary: weaponSlot = 1; break;

            case GunTypes.Infinite: weaponSlot = 2; break;

            case GunTypes.Throwable: weaponSlot = 3; break;
            }

            if (!worldSpaceUIScript)
            {
                if (_playerParent)
                {
                    worldSpaceUIScript = _playerParent.GetComponent <SCR_PlayerWorldSpaceUI>();
                }
            }
            if (worldSpaceUIScript)
            {
                if (_playerParent.GetComponent <SCR_CharacterInventory>().GetAmmo(weaponSlot) > 0)
                {
                    if (!worldSpaceUIScript.bIsDisplayed)
                    {
                        worldSpaceUIScript.ShowReloadPrompt(true);
                    }
                }
            }
        }

        if (bulletTimer <= 0 && _currentClip <= 0 && !bulletFired)
        {
            currentGunShotSource.pitch = 1;
            currentGunShotSource.PlayOneShot(emptyMagazineClip);
            bulletTimer = (1 / (_gunValues.RATEOFFIRE)) * 5.0f;
        }

        return(bulletFired);
    }