コード例 #1
0
ファイル: Minigun.cs プロジェクト: britt103/HiveArmada
        /// <summary>
        /// Shoots the miniguns. Alternates between left and right, shooting from a random barrel
        /// for aesthetic purposes. Spawns the muzzle flash emitter and plays the firing sound.
        /// </summary>
        /// <param name="position"> The position of the shot </param>
        private IEnumerator Shoot(Vector3 position)
        {
            canShoot = false;

            if (!isOverheating)
            {
                isCooling = false;

                if (overheatDecreaseDelayCoroutine != null)
                {
                    StopCoroutine(overheatDecreaseDelayCoroutine);
                    overheatDecreaseDelayCoroutine = null;
                }

                overheatDecreaseDelayCoroutine = StartCoroutine(OverheatDecreaseDelay());
            }
            else
            {
                Debug.LogError(GetType().Name + " - Shot while overheating.");
            }

            if (overheatTickCoroutine != null)
            {
                StopCoroutine(overheatTickCoroutine);
            }

            AddOverheat();

            GameObject barrel = isLeftFire
                                    ? left[Random.Range(0, left.Length)]
                                    : right[Random.Range(0, right.Length)];

            ParticleSystems muzzleFlash = muzzleFlashEmitters[muzzleFlashIndex++];

            muzzleFlash.gameObject.transform.position = barrel.transform.position;
            muzzleFlash.gameObject.transform.rotation = barrel.transform.rotation;
            muzzleFlash.play();

            if (muzzleFlashIndex >= muzzleFlashEmitters.Length)
            {
                muzzleFlashIndex = 0;
            }

            StartCoroutine(FlashTracer(barrel, position, barrel.GetComponent <LineRenderer>()));

            source.PlayOneShot(minigunShootSound);

            reference.statistics.IsFiring();
            reference.statistics.WeaponFired("Minigun", 1);
            reference.playerIdleTimer.SetIsIdle(false);

            yield return(new WaitForSeconds(1.0f / fireRate));

            isLeftFire = !isLeftFire;
            canShoot   = true;

            reference.statistics.IsNotFiring();
            reference.playerIdleTimer.SetIsIdle(true);
        }
コード例 #2
0
ファイル: LaserGun.cs プロジェクト: britt103/HiveArmada
        /// <summary>
        /// Blocks the gun from shooting based on fire rate, updates LineRenderers, plays a muzzle
        /// flash emitter, plays the gun sound and starts the FlashLaser coroutine.
        /// </summary>
        /// <param name="position"> The position of the target being shot </param>
        private IEnumerator Shoot(Vector3 position)
        {
            canShoot = false;
            GameObject laser;

            if (isLeftFire)
            {
                leftLaser.endWidth = thickness *
                                     Mathf.Max(
                    Vector3.Magnitude(left.transform.position - position),
                    1.0f);

                leftLaser.SetPosition(0, left.transform.position);
                leftLaser.SetPosition(1, position);

                laser = left;
            }
            else
            {
                rightLaser.endWidth = thickness *
                                      Mathf.Max(
                    Vector3.Magnitude(right.transform.position - position),
                    1.0f);

                rightLaser.SetPosition(0, right.transform.position);
                rightLaser.SetPosition(1, position);

                laser = right;
            }

            ParticleSystems muzzleFlash = muzzleFlashEmitters[muzzleFlashIndex++];

            muzzleFlash.gameObject.transform.position = laser.transform.position;
            muzzleFlash.gameObject.transform.rotation = laser.transform.rotation;
            muzzleFlash.play();

            if (muzzleFlashIndex >= muzzleFlashEmitters.Length)
            {
                muzzleFlashIndex = 0;
            }

            StartCoroutine(FlashLaser(isLeftFire));

            source.PlayOneShot(laserShootSound);

            reference.statistics.IsFiring();
            reference.statistics.WeaponFired("Laser Gun", 1);
            reference.playerIdleTimer.SetIsIdle(false);

            yield return(new WaitForSeconds(1.0f / fireRate));

            isLeftFire = !isLeftFire;
            canShoot   = true;

            reference.statistics.IsNotFiring();
            reference.playerIdleTimer.SetIsIdle(true);
        }
コード例 #3
0
ファイル: Projectile.cs プロジェクト: britt103/HiveArmada
        /// <summary>
        /// Updates the velocity as long as the time warp is active.
        /// </summary>
        private IEnumerator TimeWarp()
        {
            trailEmitter.play();
            while (reference.enemyAttributes.IsTimeWarped)
            {
                pRigidbody.velocity = transform.forward *
                                      reference.enemyAttributes.projectileSpeeds[ProjectileId];

                yield return(null);
            }
            trailEmitter.stop();
            timeWarpCoroutine = null;
        }
コード例 #4
0
ファイル: Player.cs プロジェクト: PedroNeto213/UnderThePeak
                    // ...

                    void Update()
                    {
                        // Input.

                        input.x = Input.GetAxis("Horizontal");
                        input.y = Input.GetAxis("Vertical");

                        if (Input.GetMouseButton(1))
                        {
                            input.y += 1.0f;
                        }

                        // Rotate.

                        Vector3 localVelocity = transform.InverseTransformDirection(rigidbody.velocity);

                        if (localVelocity.magnitude < velocityEpsilon)
                        {
                            localVelocity = Vector3.zero;
                        }

                        Quaternion lookRotation = Quaternion.identity;

                        if (localVelocity != Vector3.zero)
                        {
                            lookRotation = Quaternion.LookRotation(localVelocity);
                        }

                        rotationEulerX = Mathf.LerpAngle(rotationEulerX, lookRotation.eulerAngles.x, Time.deltaTime * turnSpeed);

                        reticleScreenPosition = RectTransformUtility.WorldToScreenPoint(reticle.canvas.worldCamera, reticle.transform.position);
                        Vector3 myScreenPosition = Camera.main.WorldToScreenPoint(transform.position);

                        Vector3 direction = reticleScreenPosition - myScreenPosition;

                        float angleToMouseTemp = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
                        float angleToMouse     = -angleToMouseTemp + 90.0f;

                        rotationEulerY = Mathf.LerpAngle(rotationEulerY, angleToMouse, Time.deltaTime * turnSpeed);

                        // Weapons.

                        if (Input.GetKey(KeyCode.E))
                        {
                            if (Input.GetMouseButton(0))
                            {
                                Bullet bullet = weapon.shoot(rigidbody.velocity);

                                if (bullet)
                                {
                                    rigidbody.AddForceAtPosition(-weapon.transform.forward * weaponRecoil, weapon.transform.position);
                                    GameManager.instance.cameraShake.shake(cameraShakeParams);
                                }
                            }
                        }
                        else if (Input.GetMouseButtonDown(0))
                        {
                            Bullet bullet = weapon.shoot(rigidbody.velocity, true);

                            if (bullet)
                            {
                                rigidbody.AddForceAtPosition(-weapon.transform.forward * weaponRecoil, weapon.transform.position);
                                GameManager.instance.cameraShake.shake(cameraShakeParams);
                            }
                        }

                        // VFX.

                        if (Input.GetKeyDown(KeyCode.Space))
                        {
                            blackHole.play();
                        }
                        if (Input.GetKeyUp(KeyCode.Space))
                        {
                            blackHole.stop();
                        }

                        // Thruster VFX.
                        // Forward-backward thrusters.

                        if (input.y > 0.0f)
                        {
                            if (!ps_thruster.isPlaying())
                            {
                                ps_thruster.play();
                            }

                            ps_thruster_reverse.stop();
                        }
                        else if (input.y < 0.0f)
                        {
                            if (!ps_thruster_reverse.isPlaying())
                            {
                                ps_thruster_reverse.play();
                            }

                            ps_thruster.stop();
                        }
                        else
                        {
                            ps_thruster.stop();
                            ps_thruster_reverse.stop();
                        }

                        // Side thrusters.

                        float rotationDelta = rotationEulerY - lastRotationEulerY;
                        float rotationDeltaRounded;

                        if (Mathf.Abs(rotationDelta) < rotationDeltaEpsilon)
                        {
                            rotationDeltaRounded = 0.0f;
                        }
                        else
                        {
                            rotationDeltaRounded = rotationDelta;
                        }

                        float rotationEulerTargetZ = MathUtility.remap(-rotationDeltaRounded,

                                                                       -deltaRotationYToRollZRange.x, deltaRotationYToRollZRange.x,
                                                                       -deltaRotationYToRollZRange.y, deltaRotationYToRollZRange.y);

                        //rotationEulerZ = -rotationEulerTargetZ;
                        rotationEulerZ = Mathf.LerpAngle(rotationEulerZ, rotationEulerTargetZ, Time.deltaTime * rollSpeed);

                        if (input.y >= 0.0f)
                        {
                            if (rotationDeltaRounded > 0.0f)
                            {
                                if (!ps_thruster_left.isPlaying())
                                {
                                    ps_thruster_left.play();
                                }

                                ps_thruster_right.stop();
                            }
                            else if (rotationDeltaRounded < 0.0f)
                            {
                                if (!ps_thruster_right.isPlaying())
                                {
                                    ps_thruster_right.play();
                                }

                                ps_thruster_left.stop();
                            }
                            else
                            {
                                ps_thruster_left.stop();
                                ps_thruster_right.stop();
                            }

                            ps_thruster_left_reverse.stop();
                            ps_thruster_right_reverse.stop();
                        }
                        else
                        {
                            if (rotationDeltaRounded < 0.0f)
                            {
                                if (!ps_thruster_left_reverse.isPlaying())
                                {
                                    ps_thruster_left_reverse.play();
                                }

                                ps_thruster_right_reverse.stop();
                            }
                            else if (rotationDeltaRounded > 0.0f)
                            {
                                if (!ps_thruster_right_reverse.isPlaying())
                                {
                                    ps_thruster_right_reverse.play();
                                }

                                ps_thruster_left_reverse.stop();
                            }
                            else
                            {
                                ps_thruster_left_reverse.stop();
                                ps_thruster_right_reverse.stop();
                            }

                            ps_thruster_left.stop();
                            ps_thruster_right.stop();
                        }
                    }
コード例 #5
0
ファイル: Enemy.cs プロジェクト: PedroNeto213/UnderThePeak
                    // ...

                    void Update()
                    {
                        // Face direction of velocity.

                        Quaternion targetRotation = Quaternion.identity;

                        if (rigidbody.velocity != Vector3.zero)
                        {
                            targetRotation = Quaternion.LookRotation(rigidbody.velocity);
                        }

                        // Smooth this rotation a bit.

                        rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * turnSpeed);

                        // VFX.

                        // Thruster VFX.
                        // Forward-backward thrusters.

                        Vector3 localVelocity = transform.InverseTransformDirection(rigidbody.velocity);

                        if (localVelocity.magnitude < velocityEpsilon)
                        {
                            localVelocity = Vector3.zero;
                        }

                        if (localVelocity.z > 0.0f)
                        {
                            if (!ps_thruster.isPlaying())
                            {
                                ps_thruster.play();
                            }

                            ps_thruster_reverse.stop();
                        }
                        else if (localVelocity.z < 0.0f)
                        {
                            if (!ps_thruster_reverse.isPlaying())
                            {
                                ps_thruster_reverse.play();
                            }

                            ps_thruster.stop();
                        }
                        else
                        {
                            ps_thruster.stop();
                            ps_thruster_reverse.stop();
                        }

                        // Side thrusters.

                        //float directionOfRotation;
                        //Vector3 directionToPlayer = transform.position - GameManager.instance.player.transform.position;

                        //if (directionToPlayer.x < 0.0f)
                        //{
                        //    directionOfRotation = 1.0f;
                        //}
                        //else
                        //{
                        //    directionOfRotation = -1.0f;
                        //}

                        //if (localVelocity.z >= 0.0f)
                        //{
                        //    if (directionOfRotation > 0.0f)
                        //    {
                        //        if (!ps_thruster_left.isPlaying())
                        //        {
                        //            ps_thruster_left.play();
                        //        }

                        //        ps_thruster_right.stop();
                        //    }
                        //    else if (directionOfRotation < 0.0f)
                        //    {
                        //        if (!ps_thruster_right.isPlaying())
                        //        {
                        //            ps_thruster_right.play();
                        //        }

                        //        ps_thruster_left.stop();
                        //    }
                        //    else
                        //    {
                        //        ps_thruster_left.stop();
                        //        ps_thruster_right.stop();
                        //    }

                        //    ps_thruster_left_reverse.stop();
                        //    ps_thruster_right_reverse.stop();
                        //}
                        //else
                        //{
                        //    if (directionOfRotation < 0.0f)
                        //    {
                        //        if (!ps_thruster_left_reverse.isPlaying())
                        //        {
                        //            ps_thruster_left_reverse.play();
                        //        }

                        //        ps_thruster_right_reverse.stop();
                        //    }
                        //    else if (directionOfRotation > 0.0f)
                        //    {
                        //        if (!ps_thruster_right_reverse.isPlaying())
                        //        {
                        //            ps_thruster_right_reverse.play();
                        //        }

                        //        ps_thruster_left_reverse.stop();
                        //    }
                        //    else
                        //    {
                        //        ps_thruster_left_reverse.stop();
                        //        ps_thruster_right_reverse.stop();
                        //    }

                        //    ps_thruster_left.stop();
                        //    ps_thruster_right.stop();
                        //}
                    }