Camera stuff is pretty tricky… you may wish to consider using Cinemachine from the Unity Package Manager.
There’s even a dedicated forum: Unity Engine - Unity Discussions
If you want to do it yourself, definitely get away from any use of the .eulerAngles property, especially additive uses. That will almost certainly lead to undesirable results. Here’s why:
Notes on clamping camera rotation and NOT using .eulerAngles because of gimbal lock:
Generally never read / write to / from eulerAngles.
The reason is gimbal lock.
Instead track your own float variable that is the heading, adjust and clamp that variable, then "drive" the camera's rotation each frame.
declare a variable float heading;
adjust it when conditions warrant:
if (conditionToTurn)
{
heading += AdjustmentWhateverYouWant;
}
clamp it
heading = Mathf.Clamp( heading, minimum, maximum);
drive the rotation to the camera transform:
cameraTransform.localRotation = Quaterion.Euler( 0, heading, 0);
How to instantly see gimbal lock for yourself:
Pretty sure this is gimbal lock. To see what I mean:
put a cube in a blank scene
using the inspector, independently rotate it a little bit around x, y, z - works as expected
now set x rotation to 90
try rotate around y and z - note that z works identically to y rotation! You can no longer rotate z!
In the context of your game, I’m not sure what the best solution would be, but there’s a few possibilities. Check out some youtube tutorials on changing gravity controllers…
All about Euler angles and rotations, by StarManta:
https://starmanta.gitbooks.io/unitytipsredux/content/second-question.html
You will always have better luck by:
setting the camera position (transform.position = …)
telling the camera to look at another position (transform.LookAt( …))