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);
}
}
}
}

