void Update() { // Exit Sample if (Input.GetKey(KeyCode.Escape)) { SceneManager.LoadScene("MainMenuScene"); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } //selection handling if (m_isManipulating) { Cursor.lockState = CursorLockMode.None; } if (Input.GetMouseButtonDown(0)) { if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out RaycastHit hit)) { if (hit.collider.GetComponent <Valve>()) { m_selectedValve = hit.collider.GetComponent <Valve>(); m_selectedValve.Select(); m_isManipulating = true; } else if (hit.collider.GetComponent <Crank>()) { m_selectedCrank = hit.collider.GetComponent <Crank>(); m_selectedCrank.Select(); m_isManipulating = true; } else if (hit.collider.GetComponent <Switch>()) { hit.collider.GetComponent <Switch>().Activate(); } } } if (Input.GetMouseButtonUp(0)) { if (m_selectedValve) { m_isManipulating = false; m_selectedValve.Deselect(); Cursor.lockState = CursorLockMode.Locked; } if (m_selectedCrank) { m_isManipulating = false; m_selectedCrank.Deselect(); Cursor.lockState = CursorLockMode.Locked; } } if (!m_isManipulating) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } // Translation var translation = GetInputTranslationDirection() * Time.deltaTime; // Speed up movement when shift key held if (Input.GetKey(KeyCode.LeftShift)) { translation *= 10.0f; } // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) boost += Input.mouseScrollDelta.y * 0.2f; translation *= Mathf.Pow(2.0f, boost); m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }