// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.L)) { Cursor.lockState = CursorLockMode.Locked; } // Check if we're selecting an element RightClickListener rightClickListener = GameObject.FindGameObjectWithTag("RightClickListener").GetComponent <RightClickListener>(); if (rightClickListener.isRightClicking) { return; } UpdateMovement(); UpdateGameObjectRotation(); CheckForInteraction(); CheckForElementUse(); }
void UpdateCameraRotation() { float mouseVerticalValue = Input.GetAxis(mouseYName); // Check if we're selecting an element RightClickListener rightClickListener = GameObject.FindGameObjectWithTag("RightClickListener").GetComponent <RightClickListener>(); if (rightClickListener.isRightClicking) { return; } const short ANALOG_TO_DEGREES = 360; if (mouseVerticalValue != 0) { // Adds the look input to the rotation of the camera. xDirection += -mouseVerticalValue * verticalSensitivity * Time.deltaTime; // If the absolute value of the x-axis rotation is greater than or equal to 1 if (Mathf.Abs(xDirection) >= 1) { // Set the ones place value of the value to 0 to loop the rotation. xDirection = xDirection % 1; } // Limits the rotation in the x-axis to the given lower and upper limits. xDirection = Mathf.Clamp(xDirection, lowerVerticalAngleLimit, upperVerticalAngleLimit); cameraHolder.transform.eulerAngles = new Vector3(xDirection * ANALOG_TO_DEGREES, transform.eulerAngles.y, transform.eulerAngles.z); // If this is the first time looking around, then: if (!dontDestroyRefs.ProgressionSystemInstance.IsCompleted(ProgressionMarks.FirstLookAround.ToString())) { dontDestroyRefs.ProgressionSystemInstance.Completed(ProgressionMarks.FirstLookAround.ToString()); } } }