If Camera Touches Player, print on console ("Death")

My game is sort of like Crossy Road. If the camera reaches up to you, you die. I created a code to print “Death” to the console when the camera’s Z location is the player’s Z location or more. It does not work though. I have assigned GameObjects and everything is fine except for this. Help is greatly appreciated as this is for a school project. Here is my code:

 public GameObject mainCamera;
 public GameObject player;

 private float cameraLocation;
 private float playerLocation;

 // Use this for initialization
 void Start()
 {

     cameraLocation = mainCamera.transform.position.z;
     playerLocation = player.transform.position.z;

 }

 // Update is called once per frame
 void Update()
 {

     if (cameraLocation <= playerLocation)
     {
         print("Death");
     }

 }

In update set the cameraLocation and playerLocation. How it should look like:

  void Update()
  {
      cameraLocation = mainCamera.transform.position.z;
      playerLocation = player.transform.position.z;
      if (cameraLocation <= playerLocation)
      {
          print("Death");
      }
 
  }