private void Update() { mMachineGunFireTimer += Time.deltaTime; mRocketLauncherFireTimer += Time.deltaTime; if (Input.GetKeyDown(KeyCode.Tab)) { if (mCurrentWeaponType == WeaponType.MachineGun) { mCurrentWeaponType = WeaponType.RocketLauncher; } else { mCurrentWeaponType = WeaponType.MachineGun; } mPlayerHandler.GetPlayerUIHandler().SwitchSelectedWeapon(); } if (Input.GetMouseButton(0) && mPlayerHandler.GetMainSystem().GetCurrentGameState() == GameState.Running) { switch (mCurrentWeaponType) { case WeaponType.MachineGun: if (mMachineGunFireTimer >= mMachineGunFireRate && mPlayerHandler.GetEnergy() >= 1) { mMachineGunFireTimer = 0.0f; mPlayerHandler.ChangePlayerEnergyBy(-1); FireProjectile(mBulletDamage, mBulletSpeed, WeaponType.MachineGun, (mFireFromRight) ? mRightHandFirePosition.transform.position : mLeftHandFirePosition.transform.position); mFireFromRight = !mFireFromRight; } break; case WeaponType.RocketLauncher: if (mRocketLauncherFireTimer >= mRocketLauncherFireRate && mPlayerHandler.GetEnergy() >= 5) { mRocketLauncherFireTimer = 0.0f; mPlayerHandler.ChangePlayerEnergyBy(-5); FireProjectile(mRocketDamage, mRocketSpeed, WeaponType.RocketLauncher, (mFireFromRight) ? mRightHandFirePosition.transform.position : mLeftHandFirePosition.transform.position); mFireFromRight = !mFireFromRight; } break; default: Debug.Log("Incorrect Projectile Type!"); break; } } }
private void Update() { if (mEnergyBallGlideTimer < 1.0f) { CanGlideToPlayer = false; mRigidbody.velocity = mGlideDirection; if (gameObject.transform.localScale.x < 0.3) { gameObject.transform.localScale = new Vector3(mEnergyBallGlideTimer, mEnergyBallGlideTimer, mEnergyBallGlideTimer); } mEnergyBallGlideTimer += Time.deltaTime * 0.2f; } else { CanGlideToPlayer = true; mRigidbody.velocity = Vector3.zero; } if (GlideTowardsPlayer && CanGlideToPlayer) { Vector3 dirToPlayer = GameConstants.Instance.PlayerObject.transform.position - transform.position; mRigidbody.velocity = dirToPlayer.normalized * mSpeedToApproachPlayer; mSpeedToApproachPlayer += Time.deltaTime * 3; } if ((GameConstants.Instance.PlayerObject.transform.position - transform.position).magnitude <= 2.0f) { AudioSystem.Instance.PlaySound("Pickup", 0.1f); GameObject EnergyPopVFXObject = PoolSystem.Instance.GetObjectFromPool(EnergyPopVFX, argActivateObject: true, argShouldExpandPool: true, argShouldCreateNonExistingPool: true); EnergyPopVFXObject.transform.position = transform.position; DeactivateVFX EnergyPopVFXObjectScript = EnergyPopVFXObject.GetComponent <DeactivateVFX>(); EnergyPopVFXObjectScript.WaitForDeactivation(); //Give Player Energy PlayerHandler playerHandler = GameConstants.Instance.PlayerObject.GetComponent <PlayerHandler>(); playerHandler.IncreaseScore((int)mEnergyToProvide); playerHandler.ChangePlayerEnergyBy(mEnergyToProvide); //Reset Energy Ball DeactivateEnergyBall(); } }