Lerp Rotation broken

So, I have been working on some camera rotation scripts and no matter what I do it always lerps to 180 degrees, unless its supposed to lerp to 0, in that case it works.

The below script controls the rotation, yLerp is set in another script, but it is not that causing the issue as I have also manually changed yLerp to 90 and it still rotates to 180, Also when I do a Debug.Log(“” + yLerp) it always says the value it is set to.

#pragma strict
static var yLerp = 0;
var speed = 2.0;
function Start () {

}

function FixedUpdate () {
transform.rotation.y = Mathf.Lerp(transform.rotation.y,yLerp, speed * Time.deltaTime);
}

‘transform.rotation’ is a Quaternion…a non-intuitive 4D construct with values in the range of -1 to 1. You can use transform.eulerAngles, but you don’t want to be assigning individual components of eulerAngles. You need to set all three at the same time. Here is a bit of code for you to play with. Note that reading a eulerAngle as I’ve done here can cause problems if your object has arbitrary rotation in the x and z axes.

#pragma strict
static var yLerp : float = 45.0;
var speed = 2.0;

function Update () {
	var angles = transform.eulerAngles;
	angles.y = Mathf.Lerp(angles.y, yLerp, speed * Time.deltaTime);
	transform.eulerAngles = angles;
}