I have this bit of code here, huge thanks to Holistic3D, to control camera rotation for looking around.
void Update () {
Vector2 md = new Vector2 (Input.GetAxisRaw ("Mouse X"), Input.GetAxisRaw ("Mouse Y"));
md = Vector2.Scale (md, new Vector2 (sensitivity * smoothing, sensitivity * smoothing));
smoothV.x = Mathf.Lerp (smoothV.x, md.x, 1f / smoothing);
smoothV.y = Mathf.Lerp (smoothV.y, md.y, 1f / smoothing);
mouseLook += smoothV;
Quaternion rotate = Quaternion.AngleAxis (-mouseLook.y, Vector3.right);
//My addition
if (rotate.x > 0) {
rotate.x = Mathf.Clamp (rotate.x, 270f, 360f);
} else {
rotate.x = Mathf.Clamp (rotate.x, 0f, 90f);
}//if & else
//End my addition
transform.localRotation = rotate;//Rotates the camera up & down
character.transform.localRotation = Quaternion.AngleAxis (mouseLook.x, character.transform.up);//Rotates the player & camera, left & right
}//Void Update
The only problem I have with it is that it doesn’t clamp the cameras X rotation. And trying to clamp rotation is extremely weird.
And when I try to clamp the rotation it clamps it to only 270 degrees, or 90 degrees.