How do I make the camera stop rotating at a certain point

So I have just started a new project and in the game that I am making the player’s camera can look left, right, up, and down by moving the mouse… I have created a system that works but the one problem is when I keep looking up/down the camera doesn’t stop, it just keeps going. This eventually leads to the camera being upside down (I attached an image of what this looks like for reference)… I have been trying to make it so my camera stops when I look directly up/down with no success. Can anyone help me with this? I am completely lost. Here is the code I have so far…

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

public class CameraMain : MonoBehaviour
{
    public Camera cam;
    public bool Bounds;

    // Start is called before the first frame update
    void Start()
    {
        Bounds = true;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetAxis("Mouse Y") != 0)
        {
            if (Bounds == true)
            {
                this.transform.Rotate(Input.GetAxis("Mouse Y") * -1, 0f, 0f);
            }
        }
    }
}


You basically want to define a minMax rotation value and then check for that before updating your rotation. You can see a well explained example implementation (here it’s a third person camera) by Sebastian Lague in this video:

In case you are building any sort of character camera, this series may generally be very helpful to you.

Hey looks like the video cant be played anymore, could you send it again please I have the exact same problem.