How to restrict a cameras max/min rotation?

Hi!

I have this huge problem of mine, and I can't find any solution to this.. Have tried meny ways but none of them works for me.

I'm still a beginner of unity, but I will learn to use it one step at a time..

Im trying to make a FPScamera myself and The problem is that it turns all the way around when you look up.. So that you eventually end up loooking forward again.. I dont want that. I want the camera to Stop moving "Up" when it has reached the point where it's actually is looking up, at the angle of 90 degrees I think it would be. The same for looking down. So my Code is:

//Simple Cam Move

//Drag player into Player transform

//Set camera as a child of Player

var rotateSensitivity = 5; 
var Player : Transform;

function Update () {
var vertic : float = Input.GetAxis("Mouse Y");
var horiz : float = Input.GetAxis("Mouse X");

if(Input.GetAxis("Mouse Y")){
    transform.Rotate(Vector3(-vertic * rotateSensitivity,0,0));
}

if(Input.GetAxis("Mouse X")){
    Player.Rotate(Vector3(0,horiz * rotateSensitivity,0));
}
}

I had in mind that i could use Mathf.Clamp to restrict it But with no sucsess.. Maby something like this?

 transform.rotation.x = Mathf.Clamp(transform.rotation.x, -10, 10);

Maby im just doin it wrong.. You tell me. Im toaly Stuck on this. Plz Help! Thx! //Edvin

Transform.rotation is a unit-length quaternion, so this:

transform.rotation.x = Mathf.Clamp(transform.rotation.x, -10, 10);

Won't do anything useful.

What I would recommend is to create a 'pitch' variable, adjust this variable in response to mouse input, use Mathf.Clamp() to clamp it as desired, and then each update, set the local rotation for the object like this (guessing at UnityScript syntax):

transform.localEulerAngles = Vector3(pitch, 0, 0);