Rotate camera up and down with mouse input with to min and max

I am trying to have a camera rotating around a globe and clamp the top and bottom of the movement. The mouse should move up and down and when it reaches
its max and min the globe should stop at that point and if I move my mouse back it move the other way.
I have tried many solution but nothing is working.
So far the best I have come up by reading many post is this script as it is moving up and down and not stopping when it reaches its min or max but now it is flipping instead.

Could someone help on this issue I cannot figure it out.
It has to be from the mouse input that the camera is moving around the globe as it is for a touch screen.
I also need the camera moving around the globe not the globe moving. I know how To move the globe and clamp the min and max .

private Ray ray;
public GameObject targetItem;
private Vector3 point;//th cooord to point where the camera look at
private RaycastHit hit;
public LayerMask touchInputMask;
private float angularSpeed = 90;
private float targetRotationAngle = 45;
private float currentRotationAngle = -45;

private float rotationX;
private float rotationY;
private float Speed = 50;

// Use this for initialization
void Start () {

    point = targetItem.transform.position;//get target cooord

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


void FixedUpdate()
    if (Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0))
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out hit, touchInputMask))
            GameObject recipient = hit.transform.gameObject;
            rotationX = Input.GetAxis("Mouse X")* Time.deltaTime*5;
            rotationY = Input.GetAxis("Mouse Y")* Time.deltaTime*5;
            if (Input.GetMouseButton(0))
                if (currentRotationAngle + rotationY > targetRotationAngle)
                    rotationY = targetRotationAngle - currentRotationAngle;
                    //Stop updating when we are going to reach the target angle.
                    enabled = false;

                transform.RotateAround(point, Vector3.right, rotationY*Speed);
                transform.LookAt(point);//make cam look at it


Idk if you still need this but for anyone finding this in the future a very lovely person on stackoverflow gave me the answer to this question.

Here’s the link to that question:

And here’s a link to the stuff I used from it:

I’m pretty sure that you can just have Camera.transform.position = Input.GetMousePosition or something like that.