'UNITY - Mouse rotating player is completely free in Unity Editor, but in webGL build, mouse rotates only till edge of screen

I have following Code to rotate player around horizontal axis

float h = mouseHorizontalSpeed * Input.GetAxis("Mouse X");
transform.Rotate(0, h, 0);

speed is 4.0f, but importantly this allows me to rotate player around horizontal axis freely in editor play mode. When mouse reaches edge of screen and I keep moving mouse further, player keeps rotating. This is great and exactly what I want. But this works in play mode in Editor.

Problem is when I make build and run in webGL mode, player will only rotate until mouse reaches edge of screen. It wont rotate further. So I can only make these half turns to either side. How can I fix this=?

Testing this with Chrome



Solution 1:[1]

Thy locking the mouse cursor in the middle of the Screen:

Cursor.lockState = CursorLockMode.Locked;

or

Cursor.lockState = CursorLockMode.Confined;

Both should work.

Solution 2:[2]

Here i use the mouse position related to the window with to increase the rotation of my character. I hope the ideia helps someone in the future.

if (Input.mousePosition.x >= Screen.width - 10)
        {
            mouseX += 1f;
            pivot.rotation = Quaternion.Euler(mouseY, mouseX, 0);

        }
        else if (Input.mousePosition.x <= -Screen.width + 10)
        {
            mouseX -= 1f;
            pivot.rotation = Quaternion.Euler(mouseY, mouseX, 0);

        }
        else
        {
            pivot.rotation = Quaternion.Euler(mouseY, mouseX, 0);

        }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kostis 1101
Solution 2 Timóteo A. Cruz