Limiting a GameObject Rotation

I have a GameObject i am trying to rotate. i do not want it to rotate beyond a certain angle. Mainly because i do not want it to complete a 360 degree rotation.

Here is the code i have been using:

	v=Input.GetAxis("VerticalMouse")*Time.deltaTime*sensetivity;
	rotationDegree=inverted*v;
	rotationDegree+=transform.rotation.x;
	Mathf.Clamp (rotationDegree,minimumRotate,maximumRotate);
	rotationDegree-=transform.rotation.x;
	transform.Rotate (rotationDegree,0,0);

Regardless of whatever value i enter to minimumRotate and maximumRotate the objects can still complte a 360 angle rotation.

You’re incorrectly using rotation.x: rotation is a quaternion, and its XYZW components have nothing to do with the rotation angles - you should use transform.eulerAngles instead:

v=Input.GetAxis("VerticalMouse")*Time.deltaTime*sensetivity;
rotationDegree=inverted*v;
var curX: float = transform.eulerAngles.x; // get the current X angle
rotationDegree += curX;
Mathf.Clamp (rotationDegree,minimumRotate,maximumRotate);
rotationDegree -= curX;
transform.Rotate (rotationDegree,0,0);

But be aware that reading eulerAngles may return weird values when there’s some rotation about more than one angle - in this case, the rotation about axes Y and Z should be zero.