Unity angles messing up

I want to make a script that limits the field of view of the player (vertically) but I’m having problem with angles…

Like the title says, I need to get current angle of the gameobject, but not in the format [0-360] degrees, I need it in the format […-90,…740] degree, for example.

I tried localEulerAngle, EulerAngle, etc. Nothing works…

(transform.localEulerAngles.x)
In editor, I could get -90 degree, but 270 with Debug.Log.

Anyone has an idea?

transform.Rotate(-Input.GetAxis("Mouse Y"), 0, 0);
    
if (transform.localEulerAngles.x < 335 && transform.localEulerAngles.x > 300)
{
   transform.localEulerAngles = new Vector3(335, 0, 0);
}
else if (transform.localEulerAngles.x > 45 && transform.localEulerAngles.x < 100)
{
   transform.localEulerAngles = new Vector3(45, 0, 0);
}

This works not so bad, but I if I move my mouse very fast, I can easily go out of bounds.

set euler Angles (that’s okay), but never GET from them.

Something like Unity - Scripting API: Vector3.Angle is more reliable :wink: