예제 #1
0
    private void HandleShootSpecialWeapon()
    {
        if (input.IsSpecialFirePressed() && !SpecialWeaponCharging && !PrimaryWeaponCharging && SpecialWeapon != null)
        {
            SpecialWeaponCharging = true;
            SpeedSpecialWeapon    = 0.5f;
        }

        if (SpecialWeaponCharging)
        {
            var maxSpeed = SpecialWeapon.MaxSpeed;
            if (SpeedSpecialWeapon != maxSpeed)
            {
                SpeedSpecialWeapon += Time.deltaTime * SpecialWeapon.SpeedStep;

                // apply charging animation
                var width = SpeedSpecialWeapon / maxSpeed * 0.6f;
                SpriteCharge.size = new Vector2(width, SpriteCharge.size.y);

                if (SpeedSpecialWeapon > maxSpeed)
                {
                    SpeedSpecialWeapon = maxSpeed;
                }
            }
        }

        if (input.IsSpecialFireReleased() && SpecialWeaponCharging)
        {
            SpecialWeaponCharging = false;
            SpriteCharge.size     = new Vector2(0, SpriteCharge.size.y);

            // throw special weapon
            var throwable = Instantiate(SpecialWeapon);
            throwable.gameObject.transform.position = Position.position + ThrowOffset;
            throwable.Thrower = Player;
            throwable.SetSpeed(ShootingDirection, SpeedSpecialWeapon);
            animator.Play("throw");
            SoundManager.instance.playThrowIt();

            SpecialWeapon = null;
        }
    }
    void WeaponShoot()
    {
        //Checking the weapon shooting type
        if (weaponManager.CurrentWeaponGetter().shootingType == WeaponShootingType.SEMIAUTO)
        {
            //Making the shot in time intervals according to fire rate
            if (Input.GetMouseButtonDown(0) && Time.time > nextTimeToFire && !weaponManager.SprintingState())
            {
                nextTimeToFire = Time.time + 1 / weaponManager.CurrentWeaponGetter().getFireRate();
                isShooting     = true;

                if (weaponManager.CurrentWeaponGetter().bulletType == WeaponBulletType.M1GARAND && ammoCount > 0)
                {
                    weaponManager.CurrentWeaponGetter().ShootingAnimation();
                    GameObject bullet = Instantiate(bulletType[0], weaponManager.CurrentWeaponGetter().muzzleFlash.transform.position, weaponManager.CurrentWeaponGetter().muzzleFlash.transform.rotation);
                    bullet.transform.parent = bulletParent;
                    weaponManager.CurrentWeaponGetter().getMuzzleFlashEffect().Play();
                    if (ammoCount != 1)
                    {
                        weaponManager.GetShootingSound().pitch = Random.Range(0.85f, 1);
                        weaponManager.GetShootingSound().Play();
                    }
                    else
                    {
                        weaponManager.GetSpecialSound().pitch = Random.Range(0.85f, 1);
                        weaponManager.GetSpecialSound().Play();
                        weaponManager.GetShootingSound().pitch = Random.Range(0.85f, 1);
                        weaponManager.GetShootingSound().Play();
                    }
                }
                else if (weaponManager.CurrentWeaponGetter().bulletType == WeaponBulletType.M1911PISTOL && ammoCount > 0)
                {
                    weaponManager.CurrentWeaponGetter().ShootingAnimation();
                    GameObject bullet = Instantiate(bulletType[1], weaponManager.CurrentWeaponGetter().muzzleFlash.transform.position, weaponManager.CurrentWeaponGetter().muzzleFlash.transform.rotation);
                    bullet.transform.parent = bulletParent;
                    weaponManager.CurrentWeaponGetter().getMuzzleFlashEffect().Play();
                    if (ammoCount != 1)
                    {
                        weaponManager.GetShootingSound().pitch = Random.Range(0.85f, 1);
                        weaponManager.GetShootingSound().Play();
                    }

                    /*else
                     * {
                     *  weaponManager.GetSpecialSound().pitch = Random.Range(0.85f, 1);
                     *  weaponManager.GetSpecialSound().Play();
                     *  weaponManager.GetShootingSound().pitch = Random.Range(0.85f, 1);
                     *  weaponManager.GetShootingSound().Play();
                     * }*/
                }
            }
        }
        else if (weaponManager.CurrentWeaponGetter().shootingType == WeaponShootingType.FULLAUTO)
        {
            if (Input.GetMouseButton(0) && Time.time > nextTimeToFire)
            {
                isShooting     = true;
                nextTimeToFire = Time.time + 1 / weaponManager.CurrentWeaponGetter().getFireRate();
                weaponManager.CurrentWeaponGetter().ShootingAnimation();
            }

            //if else for bullet type
        }
        else if (weaponManager.CurrentWeaponGetter().shootingType == WeaponShootingType.LEVER)
        {
            if (Input.GetMouseButtonDown(0) && Time.time > nextTimeToFire)
            {
                isShooting     = true;
                nextTimeToFire = Time.time + 1 / weaponManager.CurrentWeaponGetter().getFireRate();
                weaponManager.CurrentWeaponGetter().ShootingAnimation();
            }
            //if else for bullet type
        }
        else if (weaponManager.CurrentWeaponGetter().shootingType == WeaponShootingType.THROWABLE)
        {
            isShooting = false;
            if (Input.GetMouseButtonDown(0) && ammoCount > 0 && !weaponManager.SprintingState())
            {
                isAimingSelf = true;
            }

            if (isAimingSelf)
            {
                if (!Input.GetMouseButton(0) && throwableAimTime >= weaponManager.CurrentWeaponGetter().getThrowableAimingAnimation().length&& isAimingSelf)
                {
                    throwableObject = Instantiate(weaponManager.CurrentWeaponGetter().getThrowable());
                    throwableObject.transform.parent = grenadeParent;
                    throwableScript = throwableObject.transform.GetComponent <ThrowableScript>();
                    throwableScript.ThrowableTransform(weaponManager.CurrentWeaponGetter().muzzleFlash.transform);
                    throwableScript.ThrowableFire();
                    isAimingSelf = false;
                }
            }
        }
        else if (weaponManager.CurrentWeaponGetter().shootingType == WeaponShootingType.USABLE)
        {
            isShooting = false;
            if (Input.GetKey(KeyCode.F) && ammoCount > 0 && playerHealth.getHealthPoints() != 100f)
            {
                weaponManager.setUsingItemState(true);
                usageTimeCounter += Time.deltaTime;
                if (usageTimeCounter >= weaponManager.getUsageTime())
                {
                    playerHealth.setHealthPoints(100f);
                    playerHealth.setBleedingEffect(false);
                    weaponManager.setUsingItemState(false);
                    ammoCount--;
                }
            }
            else if (Input.GetKeyUp(KeyCode.F))
            {
                usageTimeCounter = 0f;
                weaponManager.setUsingItemState(false);
            }
        }
        else
        {
            isShooting = false;
        }
    }