public void shoot(bool fireInput) { if (Time.time >= firingTimer && fireInput && !isReloading) { firingTimer = Time.time + 60 / gunData.fireRate; if (gunData.currentAmmo == 0) { audioSource.PlayOneShot(gunFX.emptySound); firingTimer += gunFX.emptySound.length; return; } gunData.currentAmmo--; gunRecoiler.recoil += gunData.recoil; camRecoiler.recoil += gunData.recoil; audioSource.PlayOneShot(gunFX.shootSound); if (Random.Range(0, 100) < gunData.muzzleFireFrequency + 100) { playFX(); } Vector2 screenCenterPoint = new Vector2(Screen.width / 2, Screen.height / 2); ray = FPSCamera.ScreenPointToRay(screenCenterPoint); bulletHitController.handleHit(ray, gunData.range, gunData.power); } }
public void shoot(bool fireInput) { if (Time.time >= firingTimer && fireInput && !isReloading) { //CAlculo del siguiente tiro firingTimer = Time.time + 60 / gunData.fireRate; //no bullets in the magazine if (gunData.currentAmmo == 0) { audioSource.PlayOneShot(gunFX.emptySound); firingTimer += gunFX.emptySound.length; return; } //Decrease current ammo by one gunData.currentAmmo--; //apply recoiling GUNRecoiler.recoil += gunData.recoil; CAMRecoiler.recoil += gunData.recoil; //play shoot sound; audioSource.PlayOneShot(gunFX.shootSound); if (Random.Range(0, 100) < gunData.muzzleFireFrequency * 100)//? { playFX(); } // calculate the middle point of the screen Vector2 screenCenterPoint = new Vector2(Screen.width / 2, Screen.height / 2); //raycasting from camera ray = FPSCAMERA.ScreenPointToRay(screenCenterPoint); bulletHitController.handleHit(ray, gunData.range, gunData.power); /* if(Physics.Raycast(ray, out hit, gunData.range, impactMask)) * { * * Vector3 bulletHolePosition = hit.point + hit.normal * 0.01f; //? * //variable to hold the rotation of gun is needed * Quaternion bulletHoleRotation = Quaternion.FromToRotation(Vector3.forward, hit.normal); * GameObject hole = Instantiate(bulletHole, bulletHolePosition,bulletHoleRotation); * Debug.Log("hola"); * }*/ } }