void fireWeapon(float angle) { StartCoroutine(Effects.MuzzleFlash(gun.bulletSpawnPoint)); int bulletOffset = (int)Random.Range(-gun.AngleOffset, gun.AngleOffset + 1); if (gun.gun.name == "Shotgun") { // make a shotgun blast for (int bullets = 0; bullets <= 5; bullets++) { bulletOffset = (int)Random.Range(-gun.AngleOffset, gun.AngleOffset + 1); Instantiate(bullet, gun.bulletSpawnPoint.transform.position, Quaternion.Euler(0, 0, angle + bulletOffset)); } } else { // Shoot a bullet at the proper angle Instantiate(bullet, gun.bulletSpawnPoint.transform.position, Quaternion.Euler(0, 0, angle + bulletOffset)); } // Shake that screen, boye ScreenShaker.ShakeCamera(gun.ScreenShakeAmount); // Set a delay between the next shot nextFire = Time.time + gun.FireRate; }
private void OnTriggerEnter2D(Collider2D collision) { // If the explosion collided with an enemy, if (collision.gameObject.tag == "Enemy") { // If the enemy is a normal enemy, if (collision.gameObject.name.Contains("Enemy")) { // Get it's management script EnemyManager2 enemyMan = collision.gameObject.GetComponent <EnemyManager2>(); // Set the health to 0, maybe tweak this later so it takes health based on player damage? enemyMan.Health = 0; } // If the enemy is a mine or an asteroid or something, else { // Get the management script EnemyManager1 enemyMan = collision.gameObject.GetComponent <EnemyManager1>(); // Update it's health, it doesn't need health but it's a property so changing the value makes it do a specific thing enemyMan.Health--; } } // If the explosion collided with the player, if (collision.gameObject.name == "Player") { // Snatch the player's management script PlayerManager playerMan = collision.gameObject.GetComponent <PlayerManager>(); // Set their health to 0 after doing a double-check to make sure they're alive if (collision.gameObject != null) { playerMan.Health = 0; } } // Apply screen shake shaker.ShakeCamera(.4f); }
/// <summary> /// Instantiates certain projectiles in certain amounts based on the /// weapon parameter. /// </summary> /// <param name="weapon">The weapon that the player currently has.</param> private void fireWeapon(int weapon) { // Amount to shake the camera by float cameraShake = .05f; // * * * * * * * * * * * * // * Player Weapon Checks * // * * * * * * * * * * * * // Weapon #1: Single Fire // Fires a single bullet projectile if (weapon == 1) { Instantiate(bullet, transform.position + bulletOffset, transform.rotation); } // Weapon #2: Triple Fire // Same as normal fire, but // fires an extra bullet on each side else if (weapon == 2) { for (int reps = 15; reps >= -15; reps -= 15) { Instantiate(bullet, transform.position + bulletOffset, Quaternion.Euler(new Vector3(0, 0, reps))); } cameraShake = .1f; } // Weapon #3: Mine // Fire a slow-moving mine that explodes after x seconds // OR on contact w/ enemy else if (weapon == 3) { Instantiate(mine, transform.position + bulletOffset, transform.rotation); cameraShake = .25f; } else { Debug.Log("NO WEAPON MADE FOR WEAPON VAR #" + weapon); } // Set cooldown for next shot nextFire = Time.time + fireRate; // If the game isn't in a wait period, like in a shop, if (!gameController.waitBeforeWave && !gameController.playerMan.PoweredUp) { // Subtract fuel when they fire gameController.playerMan.Speed -= .1f; } // Apply screenshake shaker.ShakeCamera(cameraShake); // Make a lil noise GameObject noise = (GameObject)Instantiate(bulletSound, transform.position, transform.rotation); // Destroy it after so there's no garbage sitting around Destroy(noise, .5f); }
public void Shake(float duration, float shakeAmount) { value.ShakeCamera(duration, shakeAmount); }