Stop camera from going more than 90 degrees on the sides.

Hi everyone,

Currently I’m making a FPS game. I really want to make the camera stop going more than 90 degrees on the left and right sides. Any way to do it? Here is my code:

using UnityEngine;
using System.Collections;

public class MouseLook : MonoBehaviour
{
    [Header("Data")]
    public float sens;

    public Transform player;

    float xRotation;

    public Vector2 turn;

    public Vector3 deltaMove;

    public float viewRange;

    public float MaxRange;


    private void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

   
    
    //Rotation Sensitivity
    public float RotationSensitivity = 35.0f;
    public float minAngle = -45.0f;
    public float maxAngle = 45.0f;

    //Rotation Value
    float yRotate = 0.0f;

    // Update is called once per frame
    void Update()
    {

        //Rotate Y view
        yRotate += Input.GetAxis("Mouse Y") * RotationSensitivity * Time.deltaTime;
        yRotate = Mathf.Clamp(yRotate, minAngle, maxAngle);
        transform.eulerAngles = new Vector3(yRotate, 0.0f, 0.0f);

        turn.x += Input.GetAxis("Mouse X") * sens * Time.deltaTime;
        turn.y = Input.GetAxis("Mouse Y") * sens * Time.deltaTime;

        xRotation -= turn.y;
        xRotation = Mathf.Clamp(xRotation, -90, 90f);

        transform.localRotation = Quaternion.Euler(xRotation, turn.x, 0);

        
    }
}

I am not completely sure which vectors you would use for roation, since I am not advanced in updating rotation with script.
I am sure you can detect the rotation, and if it exceeds your limits you will set it back to that limit.

Example:

void Update()
{
          if(currentRotation >= maxRotation)
          {
                      // set rotation to max rotation

           }
}

The same above can be done for Minimum roation, so on either side you can not exceed limits.