Just getting started with JavaScript and unity, enjoying the learning curve however there is one gotcha that is driving me crazy, I would sincerely appreciate help on this:

I need to rotate a Camera on the x Axis between 330 and 30 degrees, I have looked at the various clamping and eulerAngles options etc

With the code below, the camera does a full rotation

var RotateOnX = Input.GetAxis("RotateOnX")
transform.Rotate(RotateOnX,0, 0);

Just not able to constrain rotation to the 60 degrees between 330 and 30.

I encountered a similar problem a while ago, and tried the clamps etc. The problem was in the transition between 0 and 360, so I’ve written a small method to handle that:

/// <summary>
/// This method ensures that a rotation is clamped between two values without flipping and snapping
/// </summary>
/// <param name="valueToClamp">The angle to be clamped</param>
/// <param name="smallValue">The leftmost angle value</param>
/// <param name="bigValue">The rightmost angle value</param>
/// <returns>The clamped angle</returns>
public static float InverseAngleClamp(float valueToClamp, float smallValue, float bigValue)
{
//inverse values to compensate for angle wrapping in the transition between 0 and 360 degrees
bigValue = 360 - bigValue;
if (valueToClamp < bigValue && valueToClamp > 180)
{
valueToClamp += bigValue - valueToClamp;
}
if (valueToClamp > smallValue && valueToClamp < 180)
{
valueToClamp += smallValue - valueToClamp;
}
return valueToClamp;
}