private void Update() { // If game ended, stop doing anything if (GameManager.Instance.GameTimeUI.GameStopped) { return; } for (int i = 0; i < _allShooters.Count; i++) { _allShooters[i].HandleEquip(_currentWeaponIndex == i); } if (!isLocalPlayer) { return; } // Handling fire if (GameManager.Instance.InputManager.Mouse1 && GameManager.Instance.LocalPlayer.PlayerStates.MoveState != PlayerStates.EMoveState.Sprinting) { // We need to first check whether the local player can fire (has ammo in his inventory, is not reloading, etc..) Shooter.CheckFireAction checkFireAction = ActiveWeapon.CheckFire(); if (checkFireAction != Shooter.CheckFireAction.DontFire) { // Now we call the fire command by the server Vector3 fireOrigin = _playerCamera.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height / 2)); Vector3 fireDirection = _playerCamera.transform.forward; CmdFire(checkFireAction, fireOrigin, fireDirection); } } if (GameManager.Instance.InputManager.A) { SwitchWeapon(1); } if (GameManager.Instance.InputManager.Z) { SwitchWeapon(-1); } if (GameManager.Instance.InputManager.R && ActiveWeapon != null && !ActiveWeapon.Reloader.IsReloading) { ActiveWeapon.Reloader.Reload(); } }
private void CmdFire(Shooter.CheckFireAction checkFireAction, Vector3 fireOrigin, Vector3 fireDirection) { // We play the fire effects for everyone: Fire sound, reload sound, destablize reticle for the local player, etc.. RpcFire(checkFireAction); // Now we only make the ray cast or instantiate the projective by the server (this one handles all the health points of everyone else) if (checkFireAction == Shooter.CheckFireAction.DoFire) { for (int i = 0; i < ActiveWeapon.NumberOfBulletsFiredAtOnce; i++) { if (i == 0) { ActiveWeapon.Fire(checkFireAction, fireOrigin, fireDirection); } else { Vector3 direction = (fireDirection * 2) + (Random.insideUnitSphere * ActiveWeapon.Spread); ActiveWeapon.Fire(checkFireAction, fireOrigin, direction); } } } }
private void RpcFire(Shooter.CheckFireAction checkFireAction) { ActiveWeapon.FireRPC(checkFireAction); }