public void FireGun() { if (!hasGun || lockMovement) { return; } if (Input.GetKeyDown(KeyCode.Mouse1) && weaponStats.Scope) { sniperScoped.SetActive(!sniperScoped.activeSelf); sniperNonScoped.SetActive(!sniperNonScoped.activeSelf); } if (curFireRate > 0) { curFireRate -= weaponStats.fireRate * Time.deltaTime; return; } if (curAmmo <= 0) { //Reload curAmmo = weaponStats.maxAmmo; // curFireRate = 2; //Removing Reload due to lack of animations } Ray ray = myCamera.GetComponent <Camera>().ScreenPointToRay(Input.mousePosition); if (Input.GetKeyDown(KeyCode.Mouse0)) { playLook.Recoil(weaponStats.recoilAmount); curFireRate = 1; curAmmo -= 1; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { NoiseBubble(transform.position); NoiseBubble(hit.point); if (hit.transform.tag == "Enemy" || hit.transform.tag == "EnemyEnforcer" || hit.transform.tag == "EnemyBoss") { hit.transform.GetComponent <PlayerMove>().curHealth -= weaponStats.Damage; if (!isPlayer) { animRec.personDamage = hit.transform.gameObject; } } if (hit.transform.tag == "Glass") { Vector3 pos = hit.point; StartCoroutine("DelayExplosion", pos); expForce = 0.34f; hit.transform.GetComponent <WallDestruction>().ohfuckimhit(); //Now we gott re-send a ray through this glass shootPos = myCamera.transform.position; StartCoroutine("SendRay", hit.point); } if (hit.transform.tag == "GlassPiece") { expForce = 0.09f; StartCoroutine("DelayExplosion", hit.point); } if (hit.transform.tag == "Wall") { GameObject bullet = Instantiate(bulletHole, hit.point, hit.transform.rotation); Destroy(bullet, 30); } } } }
private void Shoot(float cwm, float vf, float af) { for (int i = 0; i < bulletsPerShot; i++) { Vector2 randomTargetPoint = Random.insideUnitCircle * ((bsna * cwm * asm * af) + vf); Vector3 randomDir = new Vector3(randomTargetPoint.x, randomTargetPoint.y, 0f); Quaternion randomRot = Quaternion.Euler(firePos.eulerAngles) * Quaternion.Euler(randomDir); GameObject proj = PoolManager.Instance.RequestInstantiate(bulletInfo.poolIndex, firePos.position, randomRot, false); if (bulletInfo.bulletType == BulletInfo.BulletType.Bullet) { Bullet projBul = proj.GetComponent <Bullet>(); projBul.BulletInfo(bulletInfo, weaponID, false, true, -1); projBul.noWhizSound = true; projBul.InstantiateStart(); } else if (bulletInfo.bulletType == BulletInfo.BulletType.Rocket) { Rocket projRoc = proj.GetComponent <Rocket>(); projRoc.RocketInfo(bulletInfo, weaponID, false, true, -1); projRoc.InstantiateStart(); } if (Topan.Network.isConnected && wm.rootNetView) { Vector3 fwdRot = Quaternion.LookRotation(randomRot * Vector3.forward).eulerAngles; wm.rootNetView.UnreliableRPC(Topan.RPCMode.Others, "NetworkShoot", (TopanFloat)(fwdRot.x / 360f), (TopanFloat)(fwdRot.y / 360f), firePos.position); } } bsna += spreadSpeed * spreadAimFactor; if (countsAsOneBullet) { AntiHackSystem.ProtectInt("currentAmmo", currentAmmo - 1); } else { AntiHackSystem.ProtectInt("currentAmmo", currentAmmo - bulletsPerShot); } fireCount++; StopCoroutine("MuzzleControl"); StartCoroutine(MuzzleControl()); if (ejectionEnabled) { if (ejectionDelay > 0f) { StartCoroutine(EjectShell()); } else { Rigidbody shell = PoolManager.Instance.RequestInstantiate(bulletShellIndex, ejectionPos.position, ejectionPos.rotation).GetComponent <Rigidbody>(); shell.velocity = (pm.controller.velocity * 0.7f) + pm.transform.TransformDirection(DarkRef.RandomVector3(ejectionMinForce, ejectionMaxForce)); shell.angularVelocity = Random.rotation.eulerAngles * ejectionRotation; } } tss.pitchMod = Random.Range(0.95f, 1f); tss.GetComponent <AudioSource>().PlayOneShot(fireSound); if (pa != null) { pa.startAnimation = true; } float aimMod = (ac.isAiming) ? aimUpkickModifier : 1f; float crouchMod = (pm.crouching) ? crouchUpkickModifier : 1f; float extraMod = (fireCount > extraRecoilThreshold) ? 1f + Mathf.Clamp((fireCount - extraRecoilThreshold) * extraRecoilAmount, 0f, maxExtraRecoil) : 1f; pl.Recoil(recoilAmount * ((ac.isAiming) ? 0.56f : 1.0f), upKickAmount * aimMod * crouchMod * extraMod, sideKickAmount * aimMod * crouchMod * extraMod, kickInfluence, kickCameraTilt, camShakeAnim, autoReturn); dm.Kickback(kickBackAmount * 0.04f, kickSpeedFactor, kickGunTilt); shootImpulseGUI += 0.1f; ammoBar.value += 0.01f; crosshair.JoltAnimation(spreadSpeed); timeSinceLastFire = Time.time; if (currentFireMode != FireMode.BurstFire) { timer += 1f; } }