Rotate camera to lean


I am trying to achieve something quite simple and yet I can’t figure it out. I am quite new to scripting as well.

In my scene I dropped a First Person Controller. When I press the Q button I want the camera to rotate to the left as the player is leaning/looking around a corner. Same for the E button for the right side.

I created a new javascript and attached it to the Main Camera of the First Person Controller.

So I wrote the script below which doesn’t set the rotation (z) at 10 but at 165 and also changes the rotation (x). Any idea’s?

var leanLeft : boolean = false;

function Update () {
	if(Input.GetKey("q")) {

function doLeanLeft() {
	if(leanLeft == false) {
		leanLeft = true;
		transform.rotation.z = 10;
		leanLeft = false;

Uses Euler Angles.

transform.rotation = Quaternion.Euler(10,0,0);