Why is this not working?

I am trying to change the rotation of an object in the z axis, but this doesent do anything.

if(Input.GetKeyDown(KeyCode.D)){
gameObject.transform.rotation.z -= 45;
}

Some things you have to set the entire structure, not just a member. Won’t bore you with details, but one way:

var ea = gameOjbect.transform.eulerAngles;
ea.z = 45;
gameOjbect.transform.eulerAngles = ea;