private void Fire() { m_Fired = true; var shellToFire = m_Shell.GetComponent <Shell>(); var fireVector = FiringLogic.CalculateFireVector(shellToFire, m_TargetFirePosition, m_FireTransform.position, m_CurrentLaunchAngle); FireVisualClientShell(fireVector, m_FireTransform.position); m_CurrentLaunchAngle = m_MaxLaunchAngle; m_ReloadTime = m_RefireRate; if (ScreenShakeController.Instance != null) { var shaker = ScreenShakeController.Instance; var chargeAmount = Mathf.InverseLerp(m_MaxLaunchAngle, m_MinLaunchAngle, m_CurrentLaunchAngle); var magnitude = Mathf.Lerp(m_ShootShakeMinMagnitude, m_ShootShakeMaxMagnitude, chargeAmount); shaker.DoShake(m_TargetFirePosition, magnitude, m_ShootShakeDuration); } m_RecoilTime = 1; var localVector = transform.InverseTransformVector(fireVector); m_RecoilDirection = new Vector2(-localVector.x, -localVector.z); }
private void Fire() { // Change the clip to the firing clip and play it. m_FiringAudioSource.clip = m_FiringAudio; m_FiringAudioSource.Play(); Vector3 fireVector = FiringLogic.CalculateFireVector(m_Shell, m_ActiveTargetPosition, m_ShellSource.position, m_CurrentLaunchAngle); // Get a random seed to associate with projectile on all clients. // This is specifically used for the cluster bomb and any debris spawns, to ensure that their // random velocities are identical int randSeed = UnityEngine.Random.Range(int.MinValue, int.MaxValue); // Immediately fire shell on client - this provides players with the necessary feedback they want FireVisualClientShell(fireVector, m_ShellSource.position, randSeed); // Reset the launch force. This is a precaution in case of missing button events. m_CurrentLaunchAngle = m_MaxLaunchAngle; m_CurrentFireTimerCount = m_TurretFireTimer; //Instantiate a muzzzle flash object if (m_MuzzleFlashPrefab != null) { GameObject muzzleFlash = Instantiate(m_MuzzleFlashPrefab, m_ShellSource, false) as GameObject; muzzleFlash.transform.localPosition = Vector3.zero; muzzleFlash.transform.up = fireVector; } }
private void Fire() { // Set the fired flag so only Fire is only called once. m_Fired = true; //Determine which shell we should fire. Shell shellToFire = GetShellType().GetComponent <Shell>(); //Determine our firing solution based on our target location and power. Vector3 fireVector = FiringLogic.CalculateFireVector(shellToFire, m_TargetFirePosition, m_FireTransform.position, m_CurrentLaunchAngle); // Get a random seed to associate with projectile on all clients. // This is specifically used for the cluster bomb and any debris spawns, to ensure that their // random velocities are identical int randSeed = UnityEngine.Random.Range(int.MinValue, int.MaxValue); // Immediately fire shell on client - this provides players with the necessary feedback they want FireVisualClientShell(fireVector, m_FireTransform.position, randSeed); CmdFire(fireVector, m_FireTransform.position, randSeed); // Reset the launch force. This is a precaution in case of missing button events. m_CurrentLaunchAngle = m_MaxLaunchAngle; m_ReloadTime = m_RefireRate; // Small screenshake on client if (ScreenShakeController.s_InstanceExists) { ScreenShakeController shaker = ScreenShakeController.s_Instance; float chargeAmount = Mathf.InverseLerp(m_MaxLaunchAngle, m_MinLaunchAngle, m_CurrentLaunchAngle); float magnitude = Mathf.Lerp(m_ShootShakeMinMagnitude, m_ShootShakeMaxMagnitude, chargeAmount); // Scale magnitude shaker.DoShake(m_TargetFirePosition, magnitude, m_ShootShakeDuration); } m_RecoilTime = 1; Vector3 localVector = transform.InverseTransformVector(fireVector); m_RecoilDirection = new Vector2(-localVector.x, -localVector.z); }