diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 2971190cdb1..28f3a6118db 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -378,6 +378,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed case where the SceneView don't refresh when using LightExplorer with a running and Paused game (1354129) - Fixed wrong ordering in FrameSettings (Normalize Reflection Probes) - Allow negative wind speed parameter. +- Fixed impossibility to release the cursor in the template. ### Changed - Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard diff --git a/com.unity.template-hd/Assets/SampleSceneAssets/Scripts/LookWithMouse.cs b/com.unity.template-hd/Assets/SampleSceneAssets/Scripts/LookWithMouse.cs index 2aabbd014f9..f5cde4a4a14 100644 --- a/com.unity.template-hd/Assets/SampleSceneAssets/Scripts/LookWithMouse.cs +++ b/com.unity.template-hd/Assets/SampleSceneAssets/Scripts/LookWithMouse.cs @@ -20,11 +20,14 @@ public class LookWithMouse : MonoBehaviour void Start() { Cursor.lockState = CursorLockMode.Locked; + Cursor.visible = false; } // Update is called once per frame void Update() { + bool unlockPressed, lockPressed; + #if ENABLE_INPUT_SYSTEM float mouseX = 0, mouseY = 0; @@ -41,18 +44,38 @@ void Update() mouseY += value.y; } + unlockPressed = Keyboard.current.escapeKey.wasPressedThisFrame; + lockPressed = Mouse.current.leftButton.wasPressedThisFrame || Mouse.current.rightButton.wasPressedThisFrame; + mouseX *= mouseSensitivity * k_MouseSensitivityMultiplier; mouseY *= mouseSensitivity * k_MouseSensitivityMultiplier; #else float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * k_MouseSensitivityMultiplier; float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * k_MouseSensitivityMultiplier; + + unlockPressed = Input.GetKeyDown(KeyCode.Escape); + lockPressed = Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1); #endif - xRotation -= mouseY; - xRotation = Mathf.Clamp(xRotation, -90f, 90f); + if (unlockPressed) + { + Cursor.lockState = CursorLockMode.None; + Cursor.visible = true; + } + if (lockPressed) + { + Cursor.lockState = CursorLockMode.Locked; + Cursor.visible = false; + } + + if (Cursor.lockState == CursorLockMode.Locked) + { + xRotation -= mouseY; + xRotation = Mathf.Clamp(xRotation, -90f, 90f); - transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f); + transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f); - playerBody.Rotate(Vector3.up * mouseX); + playerBody.Rotate(Vector3.up * mouseX); + } } }