Why this isn't working?

Any ideas?

void Update () 
{
         int x = Screen.width / 2; 
         int y = Screen.height / 2;

         Ray ray = playerCam.GetComponent<Camera>().ScreenPointToRay(new Vector3(x, y));
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit))
             distance = hit.distance;
         {
             var p = hit.collider.GetComponent<Transform>();   //This isn't working :(
             if (p != null && distance > -3.0f)
             {
                 lookingAt = p.gameObject;
             }
         }
     }

The scope brackets are kind of pointless when not part of the if statement. Also you don’t need to use GetComponent to use the gameobject since you already got that. You Find gameobjects which hit already has and you GetComponents on that gameobject so in this case it is redundant. Lastly how can the distance ever be negative?
Here is my example of how you probably want it to look.

        if (Physics.Raycast(ray, out hit))
        {
            if (hit.distance > 3.0f)
            {
                lookingAt = hit.collider.gameObject;
            }
        }