How to lock camera Z-axes?

This worked for me as well, but is there any way to do this so that you could actually get the camera to unlock when you go downwards and lock back up? or would the camera have to transition to a different camera - if lets say you want to climb down a ladder or up to a high place thats above? So that the camera follows you but then stays at that level until you come back down