'Unity mouse y-axis locked only in build

I have a mouse look script which allows the player to look up and down in a 3D first person game. It works perfectly in the Unity Editor. Once I build the game, I can only move the mouse on x-axis. I have tried using the old and new input system, but the same result happens. I have tried setting the window mode in the player settings to fullscreen and windowed already as well as setting the input system to both.

Here is a video clip of this happening: https://www.youtube.com/watch?v=_AxX2OmkU_Y

 public class MouseLook : MonoBehaviour
 {
     Transform playerTransform;
     PlayerController playerController;
     InputMaster input;
 
     Vector2 lookDir;
 
     public float sens = 500f;
 
     private float xRotation;
 
     // Start is called before the first frame update
     void Start()
     {
         // Hide cursor
         Cursor.lockState = CursorLockMode.Locked;
 
         playerTransform = transform.parent;
         playerController = playerTransform.GetComponent<PlayerController>();
         input = playerController.Input;
     }
 
     // Update is called once per frame
     void Update()
     {
         lookDir = input.Player.Look.ReadValue<Vector2>();
 
         // Gets mouse inputs
         float moveX = lookDir.x * sens * Time.deltaTime;
         float moveY = lookDir.y * sens * Time.deltaTime;
 
         // Clamps rotation
         xRotation -= moveY;
         xRotation = Mathf.Clamp(xRotation, -90f, 90f);
 
         transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
         playerTransform.Rotate(Vector3.up * moveX);
     }
 }


Solution 1:[1]

I would use Input.GetAxis("MouseX") and Input.GetAxis("MouseY")

Make sure not to use Input.GetAxisRaw because it won't work as intended with mouse inputs :)

Documentation Link

Here is a example from the above link for mouse looking:

using UnityEngine;
using System.Collections;

// Performs a mouse look.

public class ExampleClass : MonoBehaviour
{
    float horizontalSpeed = 2.0f;
    float verticalSpeed = 2.0f;

    void Update()
    {
        // Get the mouse delta. This is not in the range -1...1
        float h = horizontalSpeed * Input.GetAxis("Mouse X");
        float v = verticalSpeed * Input.GetAxis("Mouse Y");

        transform.Rotate(v, h, 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 QwertyHJKL1234