void Update() { if (allow) { bool clickSwitchGun = !isPause && Input.GetButtonDown("SwitchGun"); bool clickTakeMedicine = !isPause && Input.GetButtonDown("TakeMedicine"); bool pressFire = !isPause && Input.GetKey(KeyCode.Mouse0); bool pressReload = !isPause && Input.GetKey(KeyCode.R); float rotationX = isPause ? 0 : Input.GetAxis("Mouse X"); float rotationY = isPause ? 0 : Input.GetAxis("Mouse Y"); bool pressJump = !isPause && Input.GetKey(KeyCode.Space); bool pressRun = !isPause && Input.GetKey(KeyCode.LeftShift); bool pressW = !isPause && Input.GetKey(KeyCode.W); bool pressS = !isPause && Input.GetKey(KeyCode.S); bool pressA = !isPause && Input.GetKey(KeyCode.A); bool pressD = !isPause && Input.GetKey(KeyCode.D); bool pressSight = !isPause && Input.GetKey(KeyCode.Mouse1); if (clickSwitchGun) { SwitchGun(); } if (clickTakeMedicine) { character.TakeMedicine(); } float recoilResult = 0.0f; Gun.GunState gunState = activeGun.Action(pressFire, pressReload, out recoilResult); recoil.AddRecoil(recoilResult); float recover = recoil.Recover(Time.deltaTime); if (sniperSight.GetSight()) { rotationX *= 0.45f; rotationY *= 0.45f; } transform.Rotate(0.0f, rotationX, 0.0f); cameraTransform.Rotate(-rotationY - recoilResult + recover, 0.0f, 0.0f); if (cameraTransform.localEulerAngles.x <= 180.0f && cameraTransform.localEulerAngles.x > 85.0f) { cameraTransform.localRotation = Quaternion.Euler(85.0f, 0, 0); } else if (cameraTransform.localEulerAngles.x > 180.0f && cameraTransform.localEulerAngles.x < 275.0f) { cameraTransform.localRotation = Quaternion.Euler(275.0f, 0, 0); } Vector3 velocity; bool isOnGround = characterController.isGrounded; if (!isOnGround) { velocityY += gravity * Time.deltaTime; } else { if (pressJump) { velocityY = jumpVelocity; } else { velocityY = 0.0f; } } if (velocityY < -maxVelocityY) { velocityY = -maxVelocityY; } int direction = 4; if (pressW && !pressS) { if (pressA && !pressD) { direction = 0; } else if (pressD && !pressA) { direction = 2; } else { direction = 1; } } else if (pressS && !pressW) { if (pressA && !pressD) { direction = 6; } else if (pressD && !pressA) { direction = 8; } else { direction = 7; } } else { if (pressA && !pressD) { direction = 3; } else if (pressD && !pressA) { direction = 5; } } bool isWalking = direction != 4; velocity.x = pressRun ? runScalarVelocityMultiple * walkVelocity [direction].x : walkVelocity [direction].x; velocity.z = pressRun ? runScalarVelocityMultiple * walkVelocity [direction].z : walkVelocity [direction].z; velocity.y = velocityY; characterController.Move(Quaternion.Euler(transform.eulerAngles) * velocity * Time.deltaTime); CharacterState characterState; if (isWalking) { if (pressRun) { characterState = CharacterState.Run; } else { characterState = CharacterState.Walk; } } else { characterState = CharacterState.Idle; } activeGun.GetAnimator().SetState(characterState, gunState); characterSound.SetWalkingSoundState(characterState); sniperSight.SetSight(activeGun == sniper && characterState != CharacterState.Run && (gunState == Gun.GunState.Fire || gunState == Gun.GunState.Idle) && pressSight); Cursor.visible = false; } else { inactiveGun.GetAnimator().SetState(CharacterState.Idle, Gun.GunState.Hide); activeGun.GetAnimator().SetState(CharacterState.Idle, Gun.GunState.Hide); characterSound.SetWalkingSoundState(CharacterState.Idle); sniperSight.SetSight(false); recoil.Reset(); Cursor.visible = true; } if (Input.GetButtonDown("Pause")) { HandlePauseClick(); } if (isPause) { Cursor.visible = true; } gameUIPanel.ShowTask(game.IsStart() && Input.GetKey(KeyCode.Tab)); }