예제 #1
0
    void FireWeapon()
    {
        bool holdingDownFire = Input.GetKey(KeyCode.Mouse0);

        if (holdingDownFire)
        {
            _shootingTime += Time.deltaTime;

            _fireTimer += Time.deltaTime;
            if (_fireTimer > _fireInterval)
            {
                _fireTimer = 0.0f;

                RaycastHit hitInfo;

                FracturedChunk chunkRaycast = FracturedChunk.ChunkRaycast(_cameraTransform.position, _cameraTransform.forward, out hitInfo);
                if (chunkRaycast)
                {
                    chunkRaycast.FromCenterImpact(hitInfo.point, _fromCenterForce, _fromCenterRadius, true);
                }
                GameAudio.PlayOneShot("GunShot");
            }
        }

        if (!holdingDownFire && _previouslyShooting)
        {
            //if the previous shot was true and current is false
            //the player just stopped shooting
            GameAudio.PlayOneShot("ShellDrop", new Dictionary <string, float>()
            {
                { "Shots", _shootingTime }
            });
            _shootingTime = 0.0f;
        }

        _previouslyShooting = holdingDownFire;
    }
예제 #2
0
    void Update()
    {
        if (ShootMode == Mode.FromCenter)
        {
            // Raycast

            if (Weapon)
            {
                Weapon.GetComponent <Renderer> ().enabled = true;
            }

            bool bShot = ShouldShoot();
            if (bShot)
            {
                _shootingTime += Time.deltaTime;
            }

            bool holdingDownFire = Input.GetKey(KeyCode.Space);
            if (!holdingDownFire && _previousShot)
            {
                //if the previous shot was true and current is false
                //the player just stopped shooting
                GameAudio.PlayOneShot("ShellDrop", new Dictionary <string, float>()
                {
                    { "Shots", _shootingTime }
                });
                _shootingTime = 0.0f;
            }

            if (bShot)
            {
                m_fRecoilTimer = RecoilDuration;
                if (AudioWeaponShot)
                {
                    AudioSource.PlayClipAtPoint(AudioWeaponShot, transform.position, WeaponShotVolume);
                }
            }

            m_bRaycastFound = false;

            RaycastHit hitInfo;

            FracturedChunk chunkRaycast = FracturedChunk.ChunkRaycast(transform.position, transform.forward, out hitInfo);

            if (chunkRaycast)
            {
                m_bRaycastFound = true;

                if (bShot)
                {
                    // Hit it!
                    chunkRaycast.FromCenterImpact(hitInfo.point, FromCenterForce, FromCenterRadius, true);
                }
            }

            _previousShot = holdingDownFire;
        }
        // Mouse-aim

        if (Input.GetMouseButton(0) && Input.GetMouseButtonDown(0) == false)
        {
            this.transform.Rotate(-(Input.mousePosition.y - m_v3MousePosition.y) * MouseSpeed, 0.0f, 0.0f);
            this.transform.RotateAround(this.transform.position, Vector3.up, (Input.mousePosition.x - m_v3MousePosition.x) * MouseSpeed);
        }

        m_v3MousePosition = Input.mousePosition;
    }