More confusion. Simple rotation problem...

function Update () {



if(Input.GetKey("d"))
{
if(transform.localRotation.y<=45)
{
transform.localRotation.y +=1;
}

}

}

So the code above. Makes me think that when the d key is pressed. 1 degree of rotation would be added onto to the current rotation, until the localRotation for y is either greater or equal to that of 45 degree. Low and behold. It keeps adding until it hits about 180.

Rotation (and localRotation) is a quaternion, not euler angles. Also localRotation is related to the child’s rotation, it’s not local space if that’s what you’re thinking. Even if you switch to euler angles, reading a single axis of a euler angle will frequently fail anyway due to the quaternion conversion, so it’s best to track rotation yourself. (Also, the phrase is “Lo and behold”. Just because I see that mistyped a lot.)

–Eric

Localrotation is a Quaternion use .localEulerAngles instead.

localRotation is a Quaternion, different from what you are expecting.

You want transform.localEulerAngles.y