Clamping camera rotation?

Hi, I’ve been trying to figure out how to clamp a camera’s rotation (I’m programming my own player character) and it doesn’t seem to be working.

	public bool DisableForStandardAsset = true;
	public float MouseSensitivity = 5.0f;
	public GameObject PlayerCamera;
	public float PlayerCameraPitchYAxisLimit = 89.0f;
	float MouseRotationY = 0f;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
		
		float MouseRotationX = Input.GetAxis("Mouse X") * MouseSensitivity;
		gameObject.transform.Rotate (0,MouseRotationX,0);

		if(DisableForStandardAsset==false)
		{
		MouseRotationY = Input.GetAxis("Mouse Y") * MouseSensitivity;
		MouseRotationY = Mathf.Clamp(MouseRotationY, -PlayerCameraPitchYAxisLimit, PlayerCameraPitchYAxisLimit);
		PlayerCamera.transform.Rotate(-MouseRotationY,0,0);
		}

Since you are using the Rotate method you are only limiting the value that you are rotating it by, you would want to limit an axis of the rotation itself:

Vector3 rot = transform.eulerAngles;
float mouseY = Input.GetAxis("Mouse Y") * MouseSensitivity;
rot.x = Mathf.Clamp(rot.x + mouseY, -yLimit, yLimit);
transform.eulerAngles = rot;