Error in looking around (x-axis)

I am a beginner and am trying to make the main cam move with the mouse. I have assigned a capsule and the main camera as the child of the player, as seen in the photo:

Now I have created a script and assigned it to the main camera, this is my script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class visuale : MonoBehaviour
{
    public Transform player;
    float sens = 300f;
    float rotaz;
    // Start is called before the first frame update
    void Start()
    {
         player = transform;
    }
   
    // Update is called once per frame
    void Update()
    {
      

        float x = Input.GetAxis("Mouse X") * Time.deltaTime * sens;
        float y = Input.GetAxis("Mouse Y") * Time.deltaTime * sens;
        rotaz -= y;
        rotaz = Mathf.Clamp(rotaz, -60f, 60f);

        transform.localRotation = Quaternion.Euler(rotaz, 0, 0);
        player.Rotate(Vector3.up * x);
      
    }
}

I’m having a problem looking around as seen in the video:

it is as if the view stops when I turn around. When I look up and down (y) it works normally.

Do you have any ideas to solve this problem?

Short answer:
I’m assuming this script goes on the camera and Transform player should be set to the capsule. In which case you do not want the line in Start() that reassigns the player transform to transform (using transform like this is referring to the transform of the gameobject that the script is attached to, in this case your camera. So you are ending up trying to reset the transform rotation twice.

TL; DR remove the line from Start() “player = transform;” Look at where your script is added to your gameobject (camera), where it says player, select the capsule.

More interesting answer:
I would recommend that you take a look at Cinemachine, the new input system and controller strategies on YouTube, for example:

and

I have no affiliation with this channel, and IMHO she goes a bit too fast, but it covers all the key points and once you know what the key points are you can always research for more information on them elsewhere.

Why?
Cinemachine (CM) is a really nice way to control cameras and takes a lot of the pain out of the awkward task of getting them to behave smoothly, manage occulsion (things getting in the way), and blend between different cameras. I wasted a lot of time trying to develop a decent camera rig before I found out about CM - don’t make the same mistake as me.

CM integrates directly with the new input system.

To start with, the new input system seems very complex compared to the old system and I still use the old system if I am trying to write a quick demo, but if you are just starting out you may as well understand the new system and get used to it. In the long run it is far more sophisticated, flexible and it will see further development.

I found getting started with Unity really daunting because there was just so much to take on, but investing some time in the complex tools at the start will really help later.