how to clamp transform.rotation

C#
 headRotation = Input.GetAxis("Mouse Y") * speed;
 transform.Rotate(0, 0, -headRotation, Space.Self);
 transform.eulerAngles.y = Mathf.Clamp(transform.eulerAngles.y, -90, 90);
Source

Also in C#: