"If" Statement

I used this code to make that if the rotation is less than 45 then rotation in Z axis is equal to 0 but doesnt matter if it is less than 45, if i Input.GetKeyUp(“a”) it allways run the code so i dont want that, please if you can improve my code, im newbie. Help, Thanks.

if (transform.rotation.z <= 45) {

if (Input.GetKeyUp (“a”)) {

transform.eulerAngles = new Vector3 (0, 0, 0);
}

}

transform.rotation is a quaternion. So quaternary.rotation.z does not represent degrees of rotation in the z axis.
You probably want transform.rotation.eulerAngles.z