rotating the camera with wasd

Your code is blindly rotating the transform. That approach won’t trivially work with clamping.

Instead you need to track the angle of up / down and clamp it.

Here’s one example, there are THOUSANDS more available in tutorial and raw code format:

http://wiki.unity3d.com/index.php/SmoothMouseLook

When you do so, keep this in mind:

Notes on clamping camera rotation and NOT using .eulerAngles because of gimbal lock: