public void Fire() { if (!stop) { if (Bazooka == true) { bulletSpawnTransform = GameObject.Find("PLSpawn").transform; if (!fire && !timedFire && !onLadder && !stuckToWall) { if (pickup.bazookaAmmo > 0f) { Vib100(); isAttacking = true; fire = true; animator.SetBool("BazookaFire", true); GetComponent <AudioSource>().PlayOneShot(Launch, 1.0f); GameObject newBullet = (GameObject)Instantiate(bulletPrefab); GameObject newKick = (GameObject)Instantiate(rocketKick); PlayerBulletController bullCon = newBullet.GetComponent <PlayerBulletController>(); ParticleFlip kickCon = newKick.GetComponent <ParticleFlip>(); bullCon.playerObject = gameObject; kickCon.playerObject = gameObject; bullCon.launchBullet(); kickCon.launchBullet(); newBullet.transform.position = bulletSpawnTransform.position; newKick.transform.position = bulletSpawnTransform.position; pickup.bazookaAmmo--; } else if (pickup.bazookaAmmo == 0f) { GetComponent <AudioSource>().PlayOneShot(outOfAmmo); } } } if (Shotgun == true) { shotgunBulletSpawn = GameObject.Find("ShotGunSpawnPoint").transform; if (!fire && !onLadder && !stuckToWall) { if (pickup.shotgunAmmo > 0f) { Vib100(); isAttacking = true; fire = true; animator.SetBool("ShotgunFire", true); GetComponent <AudioSource>().PlayOneShot(shotgunShot, 1.0f); GameObject newBullet = (GameObject)Instantiate(shotgunBullet); GameObject newKick = (GameObject)Instantiate(shotgunKick); ShotgunController bullCon = newBullet.GetComponent <ShotgunController>(); ParticleFlip kickCon = newKick.GetComponent <ParticleFlip>(); bullCon.playerObject = gameObject; kickCon.playerObject = gameObject; bullCon.ShotgunShoot(); kickCon.ShotgunShoot(); newBullet.transform.position = shotgunBulletSpawn.position; newKick.transform.position = shotgunBulletSpawn.position; pickup.shotgunAmmo--; } else if (pickup.shotgunAmmo == 0f) { GetComponent <AudioSource>().PlayOneShot(outOfAmmo); } } } if (Watergun == true) { watergunBulletSpawn = GameObject.Find("WaterGunSpawnPoint").transform; if (!fire && !onLadder && !stuckToWall) { Vib100(); isAttacking = true; fire = true; animator.SetBool("WaterGunFire", true); GetComponent <AudioSource>().PlayOneShot(watergunShot, 1.0f); GameObject newBullet = (GameObject)Instantiate(watergunBullet); GameObject newKick = (GameObject)Instantiate(watergunKick); WaterGunController bullCon = newBullet.GetComponent <WaterGunController>(); ParticleFlip kickCon = newKick.GetComponent <ParticleFlip>(); bullCon.playerObject = gameObject; kickCon.playerObject = gameObject; bullCon.WaterGunShoot(); kickCon.WaterGunShoot(); newBullet.transform.position = watergunBulletSpawn.position; newKick.transform.position = watergunBulletSpawn.position; } } if (Staff) { staffBulletSpawn = GameObject.Find("StaffSpawnPoint").transform; if (!fire && !onLadder && !stuckToWall) { staffClicks++; if (staffClicks == 1) { staffTimer = 0.5f; } else if (pickup.staffAmmo > 5f && staffClicks == 2 && !staffFired) { if (staffTimer > 0.3f) { Vib500(); isAttacking = true; fire = true; stop = true; Stop(); animator.SetBool("StaffBoom", true); GameObject newPower = Instantiate(power); newPower.transform.position = staffBulletSpawn.position; pickup.staffAmmo -= 5; } } else if (pickup.staffAmmo == 0f) { GetComponent <AudioSource>().PlayOneShot(outOfAmmo); } } } if (Granade == true) { granadeBulletSpawn = GameObject.Find("GranadeSpawnPoint").transform; if (!fire && !timedFire && !onLadder && !stuckToWall) { if (pickup.granadeAmmo > 0f) { isAttacking = true; fire = true; animator.SetBool("GranadeFire", true); } else if (pickup.granadeAmmo == 0f) { GetComponent <AudioSource>().PlayOneShot(outOfAmmo); } } } if (Boomerang == true) { boomerangBulletSpawn = GameObject.Find("BoomerangSpawnPoint").transform; if (!fire && !timedFire && !onLadder && !stuckToWall) { isAttacking = true; fire = true; animator.SetBool("BoomerangFire", true); } } } }
void Update() { animator.SetBool("grounded", grounded); animator.SetBool("walking", walking); animator.SetBool("crouching", crouching); animator.SetBool("sliding", sliding); animator.SetBool("dashing", dashing); animator.SetBool("falling", falling); animator.SetBool("wall", stuckToWall); animator.SetBool("onLadder", onLadder); animator.SetBool("jumpingThrough", jumpingThrough); if (timer > 0f) { timer -= Time.deltaTime; } if (timer < 0f) { timer = 0f; } if (timer == 0f) { WSVibrator.Cancel(); } if (orient == null) { orient = GameObject.Find("KingOrient"); } if (goodSpawn == null) { goodSpawn = GameObject.Find("EndSpawnBack"); } if (attackTimer > 0f) { attackTimer -= Time.deltaTime; } if (attackTimer == 0f && timedFire) { timedFire = false; fire = false; } if (nextFire > 0f) { nextFire -= Time.deltaTime; } if (attackTimer < 0f) { attackTimer = 0f; } if (staffTimer < 0f) { staffTimer = 0f; } if (staffTimer > 0f) { staffTimer -= Time.smoothDeltaTime; } if (staffTimer == 0) { staffClicks = 0; } if (nextFire < 0f) { nextFire = 0f; } Vector2 pos = transform.position; if (facingRight) { frontCheckTop.transform.position = new Vector2(pos.x + boxCollider.offset.x + (boxCollider.size.x / 2), pos.y + boxCollider.offset.y + (boxCollider.size.y / 2)); frontCheckBot.transform.position = new Vector2(pos.x + boxCollider.offset.x + (boxCollider.size.x / 2) + 0.1f, pos.y + boxCollider.offset.y - (boxCollider.size.y / 2) - (circleCollider.radius / 2)); } else { frontCheckTop.transform.position = new Vector2(pos.x + boxCollider.offset.x - (boxCollider.size.x / 2), pos.y + boxCollider.offset.y + (boxCollider.size.y / 2)); frontCheckBot.transform.position = new Vector2(pos.x + boxCollider.offset.x - (boxCollider.size.x / 2) - 0.1f, pos.y + boxCollider.offset.y - (boxCollider.size.y / 2) - (circleCollider.radius / 2)); } if (!stop) { hor = CFInput.GetAxis("Horizontal"); animator.SetFloat("horizontal", Mathf.Abs(hor)); } animator.SetFloat("xSpeed", Mathf.Abs(GetComponent <Rigidbody2D>().velocity.x)); animator.SetFloat("ySpeed", GetComponent <Rigidbody2D>().velocity.y); if (!OnPlatform()) { groundCollider = Physics2D.OverlapCircle(groundCheck.position, groundRadius, groundLayer); } if (keepVelocityOnGround && groundedXVelocity > 0) { if (groundedTimer > 0) { groundedTimer -= Time.deltaTime; } else { groundedXVelocity = 0; } } if (groundCollider && !jumpingThrough) { if (keepVelocityOnGround && !grounded) { groundedXVelocity = GetComponent <Rigidbody2D>().velocity.x; groundedTimer = groundedVelocityTime; } grounded = true; jumping = false; if (rotateOnSlope && !OnPlatform()) { transform.rotation = groundCollider.transform.localRotation; } if (falling) { animator.SetTrigger("stateComplete"); } falling = false; } else { transform.rotation = normalRotation; grounded = false; } if ((hor > 0 && !facingRight) || (hor < 0 && facingRight) || flipAgain) { Flip(); } if (Staff) { if (pickup.staffAmmo > 0f && staffClicks == 1 && !staffFired) { if (staffTimer < 0.3f) { Vib100(); isAttacking = true; fire = true; animator.SetBool("StaffFire", true); GetComponent <AudioSource>().PlayOneShot(staffShot, 1.0f); GameObject newBullet = Instantiate(staffBullet); StaffController bullCon = newBullet.GetComponent <StaffController>(); bullCon.playerObject = gameObject; bullCon.StaffShoot(); newBullet.transform.position = staffBulletSpawn.position; pickup.staffAmmo--; staffFired = true; } } } if (CFInput.GetButtonDown("Fire1")) { Fire(); } if (CFInput.GetButton("Fire1") && Machinegun) { machinegunBulletSpawn = GameObject.Find("MachineGunSpawnPoint").transform; if (!onLadder && !stuckToWall) { if (nextFire == 0f && pickup.machinegunAmmo > 0f) { Vib50(); isAttacking = true; nextFire = machinegunFireRate; animator.SetBool("MachineGunFire", true); GetComponent <AudioSource>().PlayOneShot(machinegunShot, 1.0f); GameObject newBullet = Instantiate(machinegunBullet); GameObject newKick = Instantiate(machinegunKick); MachineGunController bullCon = newBullet.GetComponent <MachineGunController>(); ParticleFlip kickCon = newKick.GetComponent <ParticleFlip>(); bullCon.playerObject = gameObject; kickCon.playerObject = gameObject; bullCon.MachineGunShoot(); kickCon.MachineGunShoot(); newBullet.transform.position = machinegunBulletSpawn.position; newKick.transform.position = machinegunBulletSpawn.position; pickup.machinegunAmmo--; } else if (pickup.machinegunAmmo == 0f) { isAttacking = false; animator.SetBool("MachineGunFire", false); GetComponent <AudioSource>().PlayOneShot(outOfAmmo); } } } if (CFInput.GetButtonUp("Fire1") && Machinegun) { isAttacking = false; animator.SetBool("MachineGunFire", false); } }